From ca4b4fc7bd9f7eab51dee9d2d5861f3df66b99ff Mon Sep 17 00:00:00 2001 From: Clayton Nummer Date: Sun, 4 Aug 2019 15:15:33 -0400 Subject: [PATCH] Exemption handling Handles some unexpected state behavior --- .../circadian_lighting/switch.py | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/custom_components/circadian_lighting/switch.py b/custom_components/circadian_lighting/switch.py index 9aa6c3a9..6fef883b 100644 --- a/custom_components/circadian_lighting/switch.py +++ b/custom_components/circadian_lighting/switch.py @@ -328,16 +328,25 @@ class CircadianSwitch(SwitchDevice, RestoreEntity): _LOGGER.debug(light + " Brightness Adjusted - brightness: " + str(brightness) + ", transition: " + str(transition)) def light_state_changed(self, entity_id, from_state, to_state): - _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) - if to_state.state == 'on' and from_state.state != 'on': - self.adjust_lights([entity_id], DEFAULT_INITIAL_TRANSITION) + try: + _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) + if to_state.state == 'on' and from_state.state != 'on': + self.adjust_lights([entity_id], DEFAULT_INITIAL_TRANSITION) + except: + pass def sleep_state_changed(self, entity_id, from_state, to_state): - _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) - if to_state.state == self._sleep_state or from_state.state == self._sleep_state: - self.update_switch(DEFAULT_INITIAL_TRANSITION) + try: + _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) + if to_state.state == self._sleep_state or from_state.state == self._sleep_state: + self.update_switch(DEFAULT_INITIAL_TRANSITION) + except: + pass def disable_state_changed(self, entity_id, from_state, to_state): - _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) - if from_state.state == self._disable_state: - self.update_switch(DEFAULT_INITIAL_TRANSITION) \ No newline at end of file + try: + _LOGGER.debug(entity_id + " change from " + str(from_state) + " to " + str(to_state)) + if from_state.state == self._disable_state: + self.update_switch(DEFAULT_INITIAL_TRANSITION) + except: + pass \ No newline at end of file