mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-28 21:04:19 +02:00
Squashed commit of the following:
commit5b927dbb02Merge:78395eea888afdAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 12:52:46 2023 -0500 Merge branch 'main' into adjust_adapt_until_sleep commit78395eea65Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Mon Apr 10 09:38:11 2023 +0000 Update README.md, strings.json, and services.yaml commitbc39f5e977Merge:e30b7dec4b5067Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 09:36:39 2023 +0000 Mergec4b5067b05intoe30b7debe5commitc4b5067b05Merge:7244a5f91d6065Author: Benjamin Auquite <halomastar@gmail.com> 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 commit7244a5f483Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:36:14 2023 -0500 Update const.py commit91d606586fAuthor: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Mon Apr 10 09:28:58 2023 +0000 Update README.md, strings.json, and services.yaml commit4509c0a0f1Merge:e30b7dee46d867Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 09:27:02 2023 +0000 Mergee46d867854intoe30b7debe5commite46d867854Merge:e7e266b3b61f49Author: Benjamin Auquite <halomastar@gmail.com> 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 commite7e266b5a1Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:26:47 2023 -0500 Update const.py commit3b61f49fb3Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Mon Apr 10 09:26:09 2023 +0000 Update README.md, strings.json, and services.yaml commit7f952e0658Merge:e30b7dea4d5f86Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 09:24:27 2023 +0000 Mergea4d5f861ffintoe30b7debe5commita4d5f861ffAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:24:20 2023 -0500 autofill workaround commit06dd2a5c9aAuthor: Benjamin Auquite <halomastar@gmail.com> 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 commitbca9f1bd3d, reversing changes made to840aab6158. commitbca9f1bd3dMerge:840aab62d74a31Author: Benjamin Auquite <halomastar@gmail.com> 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 commit840aab6158Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:22:07 2023 -0500 add `adapt_color_temp_until_sleep` supports backward-compatibility commit2d74a313bbAuthor: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Date: Mon Apr 10 09:14:31 2023 +0000 Update README.md, strings.json, and services.yaml commit553265a1e8Merge:e30b7deb53a5afAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 09:12:53 2023 +0000 Mergeb53a5aff68intoe30b7debe5commitb53a5aff68Author: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:11:48 2023 -0500 add new config option commit4e1c769febAuthor: Benjamin Auquite <halomastar@gmail.com> Date: Mon Apr 10 04:06:09 2023 -0500 initial commit
This commit is contained in:
parent
d1a7b9f970
commit
f0b487320d
4 changed files with 35 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue