diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 64620927..206ac588 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -155,8 +155,13 @@ CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP = ( ) DOCS[CONF_ADAPT_UNTIL_SLEEP] = ( "When enabled, Adaptive Lighting will treat sleep settings as the minimum, " - "transitioning to these values after sunset. 🌙" + "transitioning color temperature to these values after sunset. 🌙" ) +CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP = ( + "transition_brightness_until_sleep", + False, +) +DOCS[CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP] = "See " + CONF_ADAPT_UNTIL_SLEEP + "." CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0 DOCS[CONF_ADAPT_DELAY] = ( diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 98747a17..f97cf75e 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -97,6 +97,7 @@ from .const import ( ATTR_ADAPT_BRIGHTNESS, ATTR_ADAPT_COLOR, ATTR_TURN_ON_OFF_LISTENER, + CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, CONF_ADAPT_DELAY, CONF_ADAPT_UNTIL_SLEEP, CONF_AUTORESET_CONTROL, @@ -896,6 +897,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): self._sun_light_settings = SunLightSettings( name=self._name, astral_location=location, + adapt_brightness_until_sleep=data[CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP], adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP], max_brightness=data[CONF_MAX_BRIGHTNESS], max_color_temp=data[CONF_MAX_COLOR_TEMP], @@ -1436,6 +1438,7 @@ class SunLightSettings: name: str astral_location: astral.Location + adapt_brightness_until_sleep: bool adapt_until_sleep: bool max_brightness: int max_color_temp: int @@ -1576,6 +1579,9 @@ class SunLightSettings: return self.sleep_brightness if percent > 0: return self.max_brightness + if self.adapt_until_sleep and percent < 0: + delta_brightness = abs(self.min_brightness - self.sleep_brightness) + return (delta_brightness * abs(1 + percent)) + self.sleep_brightness delta_brightness = self.max_brightness - self.min_brightness percent = 1 + percent return (delta_brightness * percent) + self.min_brightness