diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index fb8ff9ed..c61187c3 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -79,6 +79,14 @@ DOCS[CONF_MIN_BRIGHTNESS] = "Minimum brightness percentage. 💡" CONF_MIN_COLOR_TEMP, DEFAULT_MIN_COLOR_TEMP = "min_color_temp", 2000 DOCS[CONF_MIN_COLOR_TEMP] = "Warmest color temperature in Kelvin. 🔥" +CONF_FLAT_LIMITS, DEFAULT_FLAT_LIMITS = "flat_limits", False +DOCS[CONF_FLAT_LIMITS] = ( + "When True, will not calculate between the" + " max/min supported limits of your light. Example: when adapting brightness to 50% while " + + CONF_MAX_BRIGHTNESS + + " is set to 80%, Adaptive Lighting will use 80% instead of 90%" +) + CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE = "only_once", False DOCS[CONF_ONLY_ONCE] = ( "Adapt lights only when they are turned on (`true`) or keep adapting them " @@ -295,6 +303,7 @@ VALIDATION_TUPLES = [ (CONF_MIN_SUNSET_TIME, NONE_STR, str), (CONF_SUNSET_OFFSET, DEFAULT_SUNSET_OFFSET, int), (CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool), + (CONF_FLAT_LIMITS, DEFAULT_FLAT_LIMITS, bool), (CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool), (CONF_ALT_DETECT_METHOD, DEFAULT_ALT_DETECT_METHOD, bool), (CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool), diff --git a/custom_components/adaptive_lighting/strings.json b/custom_components/adaptive_lighting/strings.json index 7fb0367a..869456c2 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -43,6 +43,7 @@ "min_sunset_time": "min_sunset_time: Set the earliest virtual sunset time (HH:MM:SS), allowing for later real sunsets. 🌇", "sunset_offset": "sunset_offset: Adjust sunset time with a positive or negative offset in seconds. ⏰", "only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄", + "flat_limits": "flat_limits: When True, will not calculate between the max/min supported limits of your light. Example: when adapting brightness to 50% while max_brightness is set to 80%, Adaptive Lighting will use 80% instead of 90%", "take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒", "alt_detect_method": "alt_detect_method: alt_detect_method: When true, will check for any significant changes in the opposite direction of where adaptive-lighting tried to adapt last. This is an alternative to 'detect_non_ha_changes' (default: false)", "detect_non_ha_changes": "detect_non_ha_changes: Detect non-`light.turn_on` state changes and stop adapting lights. Requires `take_over_control`. 🕵️", diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 1f208f6e..3c4942cd 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -109,6 +109,7 @@ from .const import ( CONF_ALT_DETECT_METHOD, CONF_AUTORESET_CONTROL, CONF_DETECT_NON_HA_CHANGES, + CONF_FLAT_LIMITS, CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, CONF_INITIAL_TRANSITION, CONF_INTERVAL, @@ -1086,6 +1087,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): name=self._name, astral_location=location, adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP], + flat_limits=data[CONF_FLAT_LIMITS], max_brightness=data[CONF_MAX_BRIGHTNESS], max_color_temp=data[CONF_MAX_COLOR_TEMP], min_brightness=data[CONF_MIN_BRIGHTNESS], @@ -1634,6 +1636,7 @@ class SunLightSettings: name: str astral_location: astral.Location adapt_until_sleep: bool + flat_limits: bool max_brightness: int max_color_temp: int min_brightness: int @@ -1773,8 +1776,14 @@ class SunLightSettings: return self.sleep_brightness if percent > 0: return self.max_brightness - delta_brightness = self.max_brightness - self.min_brightness percent = 1 + percent + if self.flat_limits: + if percent * 100 > self.max_brightness: + return self.max_brightness + elif percent * 100 < self.min_brightness: + return self.min_brightness + return percent * 100 + delta_brightness = self.max_brightness - self.min_brightness return (delta_brightness * percent) + self.min_brightness def calc_color_temp_kelvin(self, percent: float) -> int: diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index 91b59d6a..27873dba 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -44,6 +44,7 @@ "min_sunset_time": "min_sunset_time: Set the earliest virtual sunset time (HH:MM:SS), allowing for later real sunsets. 🌇", "sunset_offset": "sunset_offset: Adjust sunset time with a positive or negative offset in seconds. ⏰", "only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄", + "flat_limits": "flat_limits: When True, will not calculate between the max/min supported limits of your light. Example: when adapting brightness to 50% while max_brightness is set to 80%, Adaptive Lighting will use 80% instead of 90%", "take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒", "alt_detect_method": "alt_detect_method: alt_detect_method: When true, will check for any significant changes in the opposite direction of where adaptive-lighting tried to adapt last. This is an alternative to 'detect_non_ha_changes' (default: false)", "detect_non_ha_changes": "detect_non_ha_changes: Detect non-`light.turn_on` state changes and stop adapting lights. Requires `take_over_control`. 🕵️",