From abc151601b43c7df213bcf319413dcdba9b29163 Mon Sep 17 00:00:00 2001 From: Clayton Nummer Date: Sun, 4 Aug 2019 14:49:14 -0400 Subject: [PATCH] Adjust lights immediately when disable entity state changes I'm thinking about removing the disable entity option, but while it remains this is the proper behavior --- custom_components/circadian_lighting/switch.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/custom_components/circadian_lighting/switch.py b/custom_components/circadian_lighting/switch.py index 420a3d90..9aa6c3a9 100644 --- a/custom_components/circadian_lighting/switch.py +++ b/custom_components/circadian_lighting/switch.py @@ -148,6 +148,8 @@ class CircadianSwitch(SwitchDevice, RestoreEntity): track_state_change(hass, self._lights, self.light_state_changed) if self._sleep_entity is not None: track_state_change(hass, self._sleep_entity, self.sleep_state_changed) + if self._disable_entity is not None: + track_state_change(hass, self._disable_entity, self.disable_state_changed) @property def entity_id(self): @@ -333,4 +335,9 @@ class CircadianSwitch(SwitchDevice, RestoreEntity): 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) + + 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