From fb36952d635b433e452f4e7e2a2bca54878a58e6 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 3 Aug 2023 19:30:06 -0700 Subject: [PATCH] feat: add different brightness ramping mechanisms --- custom_components/adaptive_lighting/const.py | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index d2b1dc1e2..2817d5a2a 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -142,6 +142,30 @@ " for later real sunsets. 🌇" ) +CONF_BRIGHTNESS_MODE, DEFAULT_BRIGHTNESS_MODE = "brightness_mode", "default" +DOCS[CONF_BRIGHTNESS_MODE] = ( + "Brightness mode to use. Possible values are `default`, `linear`, and `tanh` " + "(uses `brightness_ramp_time_before` and `brightness_ramp_time_after`). 📈" +) +CONF_BRIGHTNESS_RAMP_TIME_BEFORE, DEFAULT_BRIGHTNESS_RAMP_TIME_BEFORE = ( + "brightness_ramp_time_before", + 3600, +) +DOCS[CONF_BRIGHTNESS_RAMP_TIME_BEFORE] = ( + "(Ignored if `brightness_mode='default'`) The duration (in seconds) to ramp up/down " + "the brightness before sunrise/sunset. The brightness starts changing at this many seconds " + "before the sunset/sunrise 📈📉" +) +CONF_BRIGHTNESS_RAMP_TIME_AFTER, DEFAULT_BRIGHTNESS_RAMP_TIME_AFTER = ( + "brightness_ramp_time_after", + 3600, +) +DOCS[CONF_BRIGHTNESS_RAMP_TIME_AFTER] = ( + "(Ignored if `brightness_mode='default'`) The duration (in seconds) to ramp up/down " + "the brightness after sunrise/sunset. The brightness starts changing at this many seconds " + "after the sunset/sunrise 📈📉." +) + CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL = "take_over_control", True DOCS[CONF_TAKE_OVER_CONTROL] = ( "Disable Adaptive Lighting if another source calls `light.turn_on` while lights " @@ -284,6 +308,27 @@ def int_between(min_int, max_int): (CONF_SUNSET_TIME, NONE_STR, str), (CONF_MIN_SUNSET_TIME, NONE_STR, str), (CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET, int), + ( + CONF_BRIGHTNESS_MODE, + DEFAULT_BRIGHTNESS_MODE, + selector.SelectSelector( + selector.SelectSelectorConfig( + options=["default", "linear", "tanh"], + multiple=False, + mode=selector.SelectSelectorMode.DROPDOWN, + ), + ), + ), + ( + CONF_BRIGHTNESS_RAMP_TIME_BEFORE, + DEFAULT_BRIGHTNESS_RAMP_TIME_BEFORE, + cv.positive_int, + ), + ( + CONF_BRIGHTNESS_RAMP_TIME_AFTER, + DEFAULT_BRIGHTNESS_RAMP_TIME_AFTER, + cv.positive_int, + ), (CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool), (CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool), (CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool), @@ -322,6 +367,8 @@ def timedelta_as_int(value): CONF_SUNSET_OFFSET: (cv.time_period, timedelta_as_int), CONF_SUNSET_TIME: (cv.time, str), CONF_MIN_SUNSET_TIME: (cv.time, str), + CONF_BRIGHTNESS_RAMP_TIME_AFTER: (cv.time_period, timedelta_as_int), + CONF_BRIGHTNESS_RAMP_TIME_BEFORE: (cv.time_period, timedelta_as_int), }