From 26797b677d8fd2fa9ad8cfcfbbe0666c4eb38a30 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Tue, 30 Aug 2022 10:48:09 -0700 Subject: [PATCH] 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