From dee6eed67f20cb7eca892c4fd710e0e88c7a337b Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 30 Aug 2022 10:29:32 -0700 Subject: [PATCH 1/4] Take care of the turn_on_event not having registered an event for entity_id --- custom_components/adaptive_lighting/switch.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 5eb29a9a..7f910702 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1512,6 +1512,11 @@ class TurnOnOffListener: transition = None turn_on_event = self.turn_on_event.get(entity_id) + if turn_on_event is None: + # This means that the light never got a 'turn_on' call that we + # registered. I am not 100% sure why this happens, but it does. + # This is a fix for #170 and #232 + return False id_turn_on = turn_on_event.context.id id_off_to_on = off_to_on_event.context.id From 1642ae8da35ec36b6cd719e00966f64b93257889 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 30 Aug 2022 10:34:36 -0700 Subject: [PATCH 2/4] Bump to 1.0.19 --- custom_components/adaptive_lighting/manifest.json | 2 +- custom_components/adaptive_lighting/switch.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index 4ac645d0..8b431d69 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -6,7 +6,7 @@ "config_flow": true, "dependencies": [], "codeowners": ["@basnijholt", "@RubenKelevra"], - "version": "1.0.18", + "version": "1.0.19", "requirements": [], "iot_class": "calculated" } diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 7f910702..4fdf1413 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1515,7 +1515,7 @@ class TurnOnOffListener: if turn_on_event is None: # This means that the light never got a 'turn_on' call that we # registered. I am not 100% sure why this happens, but it does. - # This is a fix for #170 and #232 + # This is a fix for #170 and #232. return False id_turn_on = turn_on_event.context.id From 26797b677d8fd2fa9ad8cfcfbbe0666c4eb38a30 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 30 Aug 2022 10:48:09 -0700 Subject: [PATCH 3/4] Make sure that 'settings' dict is populated when switch is off Closes #249 and #190 --- custom_components/adaptive_lighting/switch.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 4fdf1413..922d1e1d 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -793,6 +793,11 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): if "transition" in features: service_data[ATTR_TRANSITION] = transition + # The switch might be off and not have _settings set. + self._settings = self._sun_light_settings.get_settings( + self.sleep_mode_switch.is_on, transition + ) + if "brightness" in features and adapt_brightness: brightness = round(255 * self._settings["brightness_pct"] / 100) service_data[ATTR_BRIGHTNESS] = brightness From c0bc8d23da186368799abe76b4963f0c34d40f38 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 30 Aug 2022 10:49:24 -0700 Subject: [PATCH 4/4] Bump to 1.0.20 --- custom_components/adaptive_lighting/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/manifest.json b/custom_components/adaptive_lighting/manifest.json index 8b431d69..529820f3 100644 --- a/custom_components/adaptive_lighting/manifest.json +++ b/custom_components/adaptive_lighting/manifest.json @@ -6,7 +6,7 @@ "config_flow": true, "dependencies": [], "codeowners": ["@basnijholt", "@RubenKelevra"], - "version": "1.0.19", + "version": "1.0.20", "requirements": [], "iot_class": "calculated" }