Squashed commit of the following:

commit aad2eaf595
Merge: 090c0ab a888afd
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Mon Apr 10 12:52:37 2023 -0500

    Merge branch 'main' into add_flat_limits_to_configuration

commit 090c0abc6d
Author: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Date:   Mon Apr 10 09:30:40 2023 +0000

    Update README.md, strings.json, and services.yaml

commit cb27264d6a
Merge: e30b7de f18c5f1
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Mon Apr 10 09:28:50 2023 +0000

    Merge f18c5f161b into e30b7debe5

commit f18c5f161b
Author: Benjamin Auquite <halomastar@gmail.com>
Date:   Mon Apr 10 03:59:33 2023 -0500

    initial commit
This commit is contained in:
Benjamin Auquite 2023-04-11 19:09:38 -05:00
commit d1a7b9f970
4 changed files with 21 additions and 1 deletions

View file

@ -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),

View file

@ -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`. 🕵️",

View file

@ -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:

View file

@ -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`. 🕵️",