From f0b487320ddfcf0f9178362db451d4e930ebf798 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Tue, 11 Apr 2023 19:10:37 -0500 Subject: [PATCH] Squashed commit of the following: commit 5b927dbb020443b7272f7353fd056d512afe61a4 Merge: 78395ee a888afd Author: Benjamin Auquite Date: Mon Apr 10 12:52:46 2023 -0500 Merge branch 'main' into adjust_adapt_until_sleep commit 78395eea6503bad462ab38826882e480199bcdef Author: github-actions[bot] Date: Mon Apr 10 09:38:11 2023 +0000 Update README.md, strings.json, and services.yaml commit bc39f5e977b12faf03e6403fb476a396635300d4 Merge: e30b7de c4b5067 Author: Benjamin Auquite Date: Mon Apr 10 09:36:39 2023 +0000 Merge c4b5067b052527cefbfb014a1dd024550865434e into e30b7debe551e58cc6a738f7d15a4bb75d9bb545 commit c4b5067b052527cefbfb014a1dd024550865434e Merge: 7244a5f 91d6065 Author: Benjamin Auquite Date: Mon Apr 10 04:36:25 2023 -0500 Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijholt/adaptive-lighting into adjust_adapt_until_sleep commit 7244a5f48374b9c0f54ee20af5b857e94faf03eb Author: Benjamin Auquite Date: Mon Apr 10 04:36:14 2023 -0500 Update const.py commit 91d606586fd48bb9d27025f7f84e1aac50b9a926 Author: github-actions[bot] Date: Mon Apr 10 09:28:58 2023 +0000 Update README.md, strings.json, and services.yaml commit 4509c0a0f1b809d5821d003c1f336afd395e7837 Merge: e30b7de e46d867 Author: Benjamin Auquite Date: Mon Apr 10 09:27:02 2023 +0000 Merge e46d867854ad0ebe000868f4e82be03111104d7a into e30b7debe551e58cc6a738f7d15a4bb75d9bb545 commit e46d867854ad0ebe000868f4e82be03111104d7a Merge: e7e266b 3b61f49 Author: Benjamin Auquite Date: Mon Apr 10 04:26:56 2023 -0500 Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijholt/adaptive-lighting into adjust_adapt_until_sleep commit e7e266b5a19385cee711ff6ed920addf6eefb6d7 Author: Benjamin Auquite Date: Mon Apr 10 04:26:47 2023 -0500 Update const.py commit 3b61f49fb395343788530f95bf1bd4fe0cce85ee Author: github-actions[bot] Date: Mon Apr 10 09:26:09 2023 +0000 Update README.md, strings.json, and services.yaml commit 7f952e06585b62d1d3ca770a0cae3f85a5b0f8e8 Merge: e30b7de a4d5f86 Author: Benjamin Auquite Date: Mon Apr 10 09:24:27 2023 +0000 Merge a4d5f861ff2e0cadcfc33bef1a78dc3c840cdbcc into e30b7debe551e58cc6a738f7d15a4bb75d9bb545 commit a4d5f861ff2e0cadcfc33bef1a78dc3c840cdbcc Author: Benjamin Auquite Date: Mon Apr 10 04:24:20 2023 -0500 autofill workaround commit 06dd2a5c9a9d5ca983996c32123864b3ca6be41c Author: Benjamin Auquite Date: Mon Apr 10 04:23:01 2023 -0500 Revert "Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijholt/adaptive-lighting into adjust_adapt_until_sleep" This reverts commit bca9f1bd3d9428e09c5695082059e493e7085c35, reversing changes made to 840aab6158229875e04911de4a45549ad244074e. commit bca9f1bd3d9428e09c5695082059e493e7085c35 Merge: 840aab6 2d74a31 Author: Benjamin Auquite Date: Mon Apr 10 04:22:19 2023 -0500 Merge branch 'adjust_adapt_until_sleep' of https://github.com/basnijholt/adaptive-lighting into adjust_adapt_until_sleep commit 840aab6158229875e04911de4a45549ad244074e Author: Benjamin Auquite Date: Mon Apr 10 04:22:07 2023 -0500 add `adapt_color_temp_until_sleep` supports backward-compatibility commit 2d74a313bb7b6ae7d5c6eb8fb2191db0c44c69db Author: github-actions[bot] Date: Mon Apr 10 09:14:31 2023 +0000 Update README.md, strings.json, and services.yaml commit 553265a1e8cab8ab38bba57e926edd033e21f0cd Merge: e30b7de b53a5af Author: Benjamin Auquite Date: Mon Apr 10 09:12:53 2023 +0000 Merge b53a5aff68f06501c41f64070e2cc9f327f250c2 into e30b7debe551e58cc6a738f7d15a4bb75d9bb545 commit b53a5aff68f06501c41f64070e2cc9f327f250c2 Author: Benjamin Auquite Date: Mon Apr 10 04:11:48 2023 -0500 add new config option commit 4e1c769feb0a78188ed2dc49143147f634ad0a94 Author: Benjamin Auquite Date: Mon Apr 10 04:06:09 2023 -0500 initial commit --- custom_components/adaptive_lighting/const.py | 19 ++++++++++++++++++- .../adaptive_lighting/strings.json | 4 +++- custom_components/adaptive_lighting/switch.py | 12 +++++++++++- .../adaptive_lighting/translations/en.json | 4 +++- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index c61187c3..af5bdb0a 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -173,9 +173,24 @@ CONF_ADAPT_UNTIL_SLEEP, DEFAULT_ADAPT_UNTIL_SLEEP = ( False, ) DOCS[CONF_ADAPT_UNTIL_SLEEP] = ( + "This option ignores the current state of the sleep switch. " "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_COLOR_TEMP_UNTIL_SLEEP, DEFAULT_ADAPT_COLOR_TEMP_UNTIL_SLEEP = ( + "adapt_color_temp_until_sleep", + True, +) +DOCS[ + CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP +] = "Only active when `transition_until_sleep` is true." +CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP, DEFAULT_ADAPT_BRIGHTNESS_UNTIL_SLEEP = ( + "adapt_brightness_until_sleep", + False, +) +DOCS[ + CONF_ADAPT_BRIGHTNESS_UNTIL_SLEEP +] = "Only active when `transition_until_sleep` is true." CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0 DOCS[CONF_ADAPT_DELAY] = ( @@ -273,6 +288,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/strings.json b/custom_components/adaptive_lighting/strings.json index 869456c2..53fafd98 100644 --- a/custom_components/adaptive_lighting/strings.json +++ b/custom_components/adaptive_lighting/strings.json @@ -26,7 +26,9 @@ "initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️", "sleep_transition": "sleep_transition: Duration of transition when \"sleep mode\" is toggled in seconds. 😴", "transition": "transition: Duration of transition when lights change, in seconds. 🕑", - "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning to these values after sunset. 🌙", + "transition_until_sleep": "transition_until_sleep: This option ignores the current state of the sleep switch. When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning color temperature to these values after sunset. 🌙", + "adapt_brightness_until_sleep": "adapt_brightness_until_sleep: Only active when `transition_until_sleep` is true.", + "adapt_color_temp_until_sleep": "adapt_color_temp_until_sleep: Only active when `transition_until_sleep` is true.", "interval": "interval: Frequency to adapt the lights, in seconds. 🔄", "min_brightness": "min_brightness: Minimum brightness percentage. 💡", "max_brightness": "max_brightness: Maximum brightness percentage. 💡", diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 3c4942cd..6437b192 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -104,6 +104,8 @@ from .const import ( ATTR_ADAPT_BRIGHTNESS, 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_ALT_DETECT_METHOD, @@ -1086,6 +1088,8 @@ 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_color_temp_until_sleep=data[CONF_ADAPT_COLOR_TEMP_UNTIL_SLEEP], adapt_until_sleep=data[CONF_ADAPT_UNTIL_SLEEP], flat_limits=data[CONF_FLAT_LIMITS], max_brightness=data[CONF_MAX_BRIGHTNESS], @@ -1635,6 +1639,8 @@ class SunLightSettings: name: str astral_location: astral.Location + adapt_brightness_until_sleep: bool + adapt_color_temp_until_sleep: bool adapt_until_sleep: bool flat_limits: bool max_brightness: int @@ -1776,6 +1782,10 @@ class SunLightSettings: return self.sleep_brightness if percent > 0: return self.max_brightness + 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 percent = 1 + percent if self.flat_limits: if percent * 100 > self.max_brightness: @@ -1794,7 +1804,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 diff --git a/custom_components/adaptive_lighting/translations/en.json b/custom_components/adaptive_lighting/translations/en.json index 27873dba..5e4f6193 100644 --- a/custom_components/adaptive_lighting/translations/en.json +++ b/custom_components/adaptive_lighting/translations/en.json @@ -27,7 +27,9 @@ "initial_transition": "initial_transition: Duration of the first transition when lights turn from `off` to `on` in seconds. ⏲️", "sleep_transition": "sleep_transition: Duration of transition when \"sleep mode\" is toggled in seconds. 😴", "transition": "transition: Duration of transition when lights change, in seconds. 🕑", - "transition_until_sleep": "transition_until_sleep: When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning to these values after sunset. 🌙", + "transition_until_sleep": "transition_until_sleep: This option ignores the current state of the sleep switch. When enabled, Adaptive Lighting will treat sleep settings as the minimum, transitioning color temperature to these values after sunset. 🌙", + "adapt_brightness_until_sleep": "adapt_brightness_until_sleep: Only active when `transition_until_sleep` is true.", + "adapt_color_temp_until_sleep": "adapt_color_temp_until_sleep: Only active when `transition_until_sleep` is true.", "interval": "interval: Frequency to adapt the lights, in seconds. 🔄", "min_brightness": "min_brightness: Minimum brightness percentage. 💡", "max_brightness": "max_brightness: Maximum brightness percentage. 💡",