Support Garage Doors in HomeKit#13796
Support Garage Doors in HomeKit#13796cdce8p merged 1 commit intohome-assistant:devfrom marthoc:homekit-garage-door
Conversation
There was a problem hiding this comment.
'homeassistant.const.STATE_OPEN' imported but unused
There was a problem hiding this comment.
line too long (84 > 79 characters)
There was a problem hiding this comment.
You don't need to change the comment for `domain == 'cover'. That's just for covers, since they aren't fully supported yet.
Regarding the if statement, maybe use:
if device_class == 'garage' and \
features & (SUPPORT_OPEN | SUPPORT_CLOSE):
_LOGGER.debug('Add "%s" as "%s"',
state.entity_id, 'GarageDoorOpener')
return TYPES['GarageDoorOpener'](hass, state.entity_id, state.name,
aid=aid)
elif features & SUPPORT_SET_POSITION:
_LOGGER.debug('Add "%s" as "%s"',
state.entity_id, 'WindowCovering')
return TYPES['WindowCovering'](hass, state.entity_id, state.name,
aid=aid)That way you also catch the corner case that a garage door somehow supports set_cover_position.
There was a problem hiding this comment.
You can combine those if statements:
if value == 0:
self.char_current_state.set_value(2)
self.hass.components.cover.open_cover(self.entity_id)
elif value == 1:
self.char_current_state.set_value(3)
self.hass.components.cover.close_cover(self.entity_id)There was a problem hiding this comment.
Use this instead:
def update_state(self, entity_id=None, old_state=None, new_state=None):
"""Update cover state after state changed."""
if new_state is None:
return
hass_state = new_state.state
if hass_state in (STATE_OPEN, STATE_CLOSED):
current_state = 0 if hass_state == STATE_OPEN else 1
self.char_current_state.set_value(current_state)
if not self.flag_target_state:
self.char_target_state.set_value(current_state)
self.flag_target_state = FalseYou can remove self.current_state, since only the states open and closed will be handled that way. Opening, Closing, etc. will be ignored.
There was a problem hiding this comment.
You don't need to add this char if it's not used.
There was a problem hiding this comment.
'homeassistant.components.cover.SUPPORT_STOP' imported but unused
|
Thanks @cdce8p for the review comments! I pushed a bunch of fixes to address your comments and the Hound issues. Two questions:
Are there covers that don't support OPEN and CLOSE? Just wondering if the bitwise AND is necessary here or if device_class garage is sufficient; not that including the SUPPORT_OPEN | SUPPORT_CLOSE section is harmful in any way (and I suppose it does protect against some strange cover implementation from breaking HomeKit). Issue #13782 raises the problem of some garage door covers that support set_position being wrongly added to HomeKit now as WindowCoverings so the reordering in this section should close that issue.
|
|
To 1.: It's just a fail safe. I'm not sure if there are garage doors that only support To 2.: We are working on a solution for the |
|
Can you add tests and the GitHub doc? |
|
Just pushed some tests; will open a doc PR shortly. Here's my thinking on the update_state method: with the code as it currently stands, if the door's My thinking was that it would be better to at least catch the UNKNOWN/UNAVAILABLE states and change the state in HomeKit to open (given the lack of a better HomeKit state like Unknown) to at least alert the user that something had gone wrong. But, I realize that this may not be the best way to do it. Also: would you like me to remove CHAR_OBSTRUCTION_DETECTED from .const given that we aren't using it, or should I leave it in in the event we can support it in the future? Edit: I suppose I'll need to remove it since it's causing the linting to fail. |
|
Doc PR opened and I removed CHAR_OBSTRUCTION_DETECTED - this should solve the linting issue. |
I understand your point. Until there is a good solution (see ikalchev/HAP-python#75), I would like to stay consistent over all different types and the way they are handling those cases is by not reacting to them. During #13707 we introduced some changes to the homekit core. If it's ok with you, I would rebase your branch and push the required changes before merging this PR. |
|
@cdce8p Re: the not reacting to UNKNOWN/UNAVAILABLE states, I agree with you. Just wanted to make sure we are on the same page. Do you want me to do the rebase or are you saying you'll do it? If you want to do it, please go ahead. |
I already started ;) Should be done soon. |
* Add tests
cdce8p
left a comment
There was a problem hiding this comment.
Only waiting for travis to finish, before I merge it.
|
Thanks 🥇 |
|
Spent. 3 days. working. on exactly this. Rebase nightmare until I understand @marthoc did it! Life is a b*tch ! Thanks ! |
Description:
Add support for garage doors in HomeKit:
device_class: garage(added viacustomize:).Related issue (if applicable): #13782
Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#5155
Example entry for
configuration.yaml(if applicable):Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices: