Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional property to HomeKitSwitch to show whether the Homekit outlet is in use #17448

Merged
merged 2 commits into from
Nov 6, 2018

Conversation

drndos
Copy link
Contributor

@drndos drndos commented Oct 14, 2018

Description:

This pull request adds a feature where you get additional property to your switch that is representing Homekit outlet indicating whether the actual outlet is in use or not. Tested on Koogeek P1EU and working.
image

Related issue (if applicable):

Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#<home-assistant.io PR number goes here>

Example entry for configuration.yaml (if applicable):

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • N/A New dependencies have been added to the REQUIREMENTS variable (example).
  • N/A New dependencies are only imported inside functions that use them (example).
  • N/A New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • N/A New files were added to .coveragerc.

If the code does not interact with devices:

  • N/A Tests have been added to verify that the new code works.

@@ -62,3 +70,20 @@ def turn_off(self, **kwargs):
'iid': self._chars['on'],
'value': False}]
self.put_characteristics(characteristics)

@property
def state_attributes(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be device_state_attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok so base entities are using state_attributes and platforms like homekit should use device_state_attributes. Is that correct ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for clarification. I am just learning how to contribute and use things properly. I appreciate your time and help :)

return data

@property
def outlet_in_use(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need a property. Just assign to a regular instance attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

"""Return the optional state attributes."""
data = {}

for prop, attr in PROP_TO_ATTR.items():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's only one attribute we don't need a dict or use getattr. Keep it simple for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Can be merged when build passes.

@balloob balloob merged commit 24efda2 into home-assistant:dev Nov 6, 2018
@ghost ghost removed the in progress label Nov 6, 2018
@balloob balloob mentioned this pull request Nov 29, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Feb 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants