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

Ignore duplicate state changes GarageDoor HomeKit #18149

Merged
merged 2 commits into from Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions homeassistant/components/homekit/type_covers.py
Expand Up @@ -46,10 +46,12 @@ def set_state(self, value):

params = {ATTR_ENTITY_ID: self.entity_id}
if value == 0:
self.char_current_state.set_value(3)
if self.char_current_state.value != value:
self.char_current_state.set_value(3)
self.call_service(DOMAIN, SERVICE_OPEN_COVER, params)
elif value == 1:
self.char_current_state.set_value(2)
if self.char_current_state.value != value:
self.char_current_state.set_value(2)
self.call_service(DOMAIN, SERVICE_CLOSE_COVER, params)

def update_state(self, new_state):
Expand Down
19 changes: 18 additions & 1 deletion tests/components/homekit/test_type_covers.py
Expand Up @@ -80,13 +80,30 @@ async def test_garage_door_open_close(hass, hk_driver, cls, events):
hass.states.async_set(entity_id, STATE_CLOSED)
await hass.async_block_till_done()

await hass.async_add_job(acc.char_target_state.client_update_value, 1)
await hass.async_block_till_done()
assert acc.char_current_state.value == 1
assert acc.char_target_state.value == 1
assert len(events) == 2
assert events[-1].data[ATTR_VALUE] is None

await hass.async_add_job(acc.char_target_state.client_update_value, 0)
await hass.async_block_till_done()
assert call_open_cover
assert call_open_cover[0].data[ATTR_ENTITY_ID] == entity_id
assert acc.char_current_state.value == 3
assert acc.char_target_state.value == 0
assert len(events) == 2
assert len(events) == 3
assert events[-1].data[ATTR_VALUE] is None

hass.states.async_set(entity_id, STATE_OPEN)
await hass.async_block_till_done()

await hass.async_add_job(acc.char_target_state.client_update_value, 0)
await hass.async_block_till_done()
assert acc.char_current_state.value == 0
assert acc.char_target_state.value == 0
assert len(events) == 4
assert events[-1].data[ATTR_VALUE] is None


Expand Down