From 1c952091d4479823a8f1657101b0594b41bbb5d1 Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sun, 14 Oct 2018 13:57:19 -0400 Subject: [PATCH 1/2] HomeKit: Ignore Garage command if target state is current state I have a HomeKit automation that makes sure my garage is closed at a certain time. If the garage was already closed, it would improperly call the service then set the state as closing. Home Assistant would safely ignore the service call, but HomeKit would show the wrong state (closing). This code adds a check to ensure the the target state is different than the current state before issuing a service call. --- homeassistant/components/homekit/type_covers.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/homeassistant/components/homekit/type_covers.py b/homeassistant/components/homekit/type_covers.py index cf0620a4e30d50..2815d59f5c132c 100644 --- a/homeassistant/components/homekit/type_covers.py +++ b/homeassistant/components/homekit/type_covers.py @@ -41,6 +41,15 @@ def __init__(self, *args): def set_state(self, value): """Change garage state if call came from HomeKit.""" + + # Check to make sure the target state is different than current state + current_value = self.char_current_state.get_value() + + if (current_value == value): + # We are already in target state so ignore. + _LOGGER.debug('%s: Ingoring set state to %d. Current state is %d', self.entity_id, value, current_value) + return + _LOGGER.debug('%s: Set state to %d', self.entity_id, value) self.flag_target_state = True From 7306425220a0b8a70ecccfde64735bbb17274617 Mon Sep 17 00:00:00 2001 From: Austin Drummond Date: Sun, 14 Oct 2018 14:03:50 -0400 Subject: [PATCH 2/2] fix lint errors --- homeassistant/components/homekit/type_covers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/homekit/type_covers.py b/homeassistant/components/homekit/type_covers.py index 2815d59f5c132c..9256749423e35a 100644 --- a/homeassistant/components/homekit/type_covers.py +++ b/homeassistant/components/homekit/type_covers.py @@ -41,15 +41,15 @@ def __init__(self, *args): def set_state(self, value): """Change garage state if call came from HomeKit.""" - + # Check to make sure the target state is different than current state current_value = self.char_current_state.get_value() if (current_value == value): # We are already in target state so ignore. - _LOGGER.debug('%s: Ingoring set state to %d. Current state is %d', self.entity_id, value, current_value) + _LOGGER.debug('%s: Skip set state to %d.', self.entity_id, value) return - + _LOGGER.debug('%s: Set state to %d', self.entity_id, value) self.flag_target_state = True