From 26ba4a56e8e457a48dc8cbeda2783455b2a66211 Mon Sep 17 00:00:00 2001 From: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Mon, 5 Nov 2018 16:42:19 +0100 Subject: [PATCH] Ignore duplicate state changes GarageDoor HomeKit (#18149) * Ignore duplicate state changes GarageDoor HomeKit * Don't ignore service_call --- .../components/homekit/type_covers.py | 6 ++++-- tests/components/homekit/test_type_covers.py | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homekit/type_covers.py b/homeassistant/components/homekit/type_covers.py index 840800f730b..b3beb11c8b6 100644 --- a/homeassistant/components/homekit/type_covers.py +++ b/homeassistant/components/homekit/type_covers.py @@ -46,10 +46,12 @@ class GarageDoorOpener(HomeAccessory): 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): diff --git a/tests/components/homekit/test_type_covers.py b/tests/components/homekit/test_type_covers.py index c32abaef0dd..a39af399dce 100644 --- a/tests/components/homekit/test_type_covers.py +++ b/tests/components/homekit/test_type_covers.py @@ -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