diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 206ac588..173bd095 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -157,9 +157,14 @@ DOCS[CONF_ADAPT_UNTIL_SLEEP] = ( "When enabled, Adaptive Lighting will treat sleep settings as the minimum, " "transitioning color temperature to these values after sunset. 🌙" ) +CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, DEFAULT_ADAPT_COLOR_TEMP_UNTIL_SLEEP = ( + "adapt_color_temp_until_sleep", + True, +) +DOCS[CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP] = "See " + CONF_ADAPT_UNTIL_SLEEP + "." CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP = ( - "transition_brightness_until_sleep", - False, + "adapt_brightness_until_sleep", + True, ) DOCS[CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP] = "See " + CONF_ADAPT_UNTIL_SLEEP + "." @@ -236,6 +241,8 @@ VALIDATION_TUPLES = [ (CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION), (CONF_TRANSITION, DEFAULT_TRANSITION, VALID_TRANSITION), (CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP, bool), + (CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP, bool), + (CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, DEFAULT_ADAPT_COLOR_TEMP_UNTIL_SLEEP, bool), (CONF_INTERVAL, DEFAULT_INTERVAL, cv.positive_int), (CONF_MIN_BRIGHTNESS, DEFAULT_MIN_BRIGHTNESS, int_between(1, 100)), (CONF_MAX_BRIGHTNESS, DEFAULT_MAX_BRIGHTNESS, int_between(1, 100)), diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index f97cf75e..37f40188 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -98,6 +98,7 @@ from .const import ( ATTR_ADAPT_COLOR, ATTR_TURN_ON_OFF_LISTENER, CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, + CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP, CONF_ADAPT_DELAY, CONF_ADAPT_UNTIL_SLEEP, CONF_AUTORESET_CONTROL, @@ -898,6 +899,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): name=self._name, astral_location=location, adapt_brightness_until_sleep=data[CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP], + adapt_color_temp_until_sleep=data[CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP], adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP], max_brightness=data[CONF_MAX_BRIGHTNESS], max_color_temp=data[CONF_MAX_COLOR_TEMP], @@ -1439,6 +1441,7 @@ class SunLightSettings: name: str astral_location: astral.Location adapt_brightness_until_sleep: bool + adapt_color_temp_until_sleep: bool adapt_until_sleep: bool max_brightness: int max_color_temp: int @@ -1579,7 +1582,7 @@ class SunLightSettings: return self.sleep_brightness if percent > 0: return self.max_brightness - if self.adapt_until_sleep and percent < 0: + if self.adapt_until_sleep and self.adapt_brightness_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 @@ -1594,7 +1597,7 @@ class SunLightSettings: return 5 * round(ct / 5) # round to nearest 5 if percent == 0 or not self.adapt_until_sleep: return self.min_color_temp - if self.adapt_until_sleep and percent < 0: + if self.adapt_until_sleep and self.adapt_color_temp_until_sleep and percent < 0: delta = abs(self.min_color_temp - self.sleep_color_temp) ct = (delta * abs(1 + percent)) + self.sleep_color_temp return 5 * round(ct / 5) # round to nearest 5