Make sure that 'settings' dict is populated when switch is off

Closes #249 and #190
This commit is contained in:
Bas Nijholt 2022-08-30 10:48:09 -07:00
commit 26797b677d

View file

@ -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