Merge pull request #326 from basnijholt/fix_no_settings

Make sure that 'settings' dict is populated when switch is off
This commit is contained in:
Bas Nijholt 2022-08-30 10:53:06 -07:00 committed by GitHub
commit 49fb9d8686
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View file

@ -6,7 +6,7 @@
"config_flow": true,
"dependencies": [],
"codeowners": ["@basnijholt", "@RubenKelevra"],
"version": "1.0.19",
"version": "1.0.20",
"requirements": [],
"iot_class": "calculated"
}

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