From d1a7b9f9709d61905e2bf89673c41c49dcb9e8f6 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Tue, 11 Apr 2023 19:09:38 -0500 Subject: [PATCH] Squashed commit of the following: commit aad2eaf595e21d1aec83772c935507957c1c9708 Merge: 090c0ab a888afd Author: Benjamin Auquite Date: Mon Apr 10 12:52:37 2023 -0500 Merge branch 'main' into add_flat_limits_to_configuration commit 090c0abc6d9e16d5cc41af52daeecb2bc3891be1 Author: github-actions[bot] Date: Mon Apr 10 09:30:40 2023 +0000 Update README.md, strings.json, and services.yaml commit cb27264d6a6f956a844039fdd11e8941bd6f48d1 Merge: e30b7de f18c5f1 Author: Benjamin Auquite Date: Mon Apr 10 09:28:50 2023 +0000 Merge f18c5f161b5b6a6bbe6420fce745b57743e0faa6 into e30b7debe551e58cc6a738f7d15a4bb75d9bb545 commit f18c5f161b5b6a6bbe6420fce745b57743e0faa6 Author: Benjamin Auquite Date: Mon Apr 10 03:59:33 2023 -0500 initial commit --- custom_components/adaptive_lighting/const.py | 9 +++++++++ custom_components/adaptive_lighting/strings.json | 1 + custom_components/adaptive_lighting/switch.py | 11 ++++++++++- .../adaptive_lighting/translations/en.json | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) 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`. 🕵️",