From 4e1c769feb0a78188ed2dc49143147f634ad0a94 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Mon, 10 Apr 2023 04:06:09 -0500 Subject: [PATCH 1/2] initial commit --- custom_components/adaptive_lighting/switch.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 98747a17..ccc0e542 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1576,6 +1576,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 From b53a5aff68f06501c41f64070e2cc9f327f250c2 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Mon, 10 Apr 2023 04:11:48 -0500 Subject: [PATCH 2/2] add new config option --- custom_components/adaptive_lighting/const.py | 7 ++++++- custom_components/adaptive_lighting/switch.py | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) 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 ccc0e542..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