mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-16 16:54:04 +02:00
fix: make zero brightness adaptation terminal
This commit is contained in:
parent
9ecffe5125
commit
c373e86043
9 changed files with 333 additions and 8 deletions
|
|
@ -130,6 +130,10 @@ def _is_attribute_satisfied(key: str, value: Any, attributes: dict[str, Any]) ->
|
|||
if not isinstance(current, (int, float)) or not isinstance(value, (int, float)):
|
||||
return value == current
|
||||
if key == ATTR_BRIGHTNESS:
|
||||
# Zero is an off command, so it must not be treated as equivalent to a
|
||||
# nearby nonzero brightness in either direction.
|
||||
if value == 0 or current == 0:
|
||||
return value == current
|
||||
return abs(value - current) <= BRIGHTNESS_TOLERANCE
|
||||
if key == ATTR_COLOR_TEMP_KELVIN and value > 0 and current > 0:
|
||||
# Compare in mired space: most integrations quantize color temperature
|
||||
|
|
@ -283,6 +287,14 @@ def prepare_adaptation_data(
|
|||
entity_id,
|
||||
service_data,
|
||||
)
|
||||
if service_data.get(ATTR_BRIGHTNESS) == 0:
|
||||
# Home Assistant treats brightness zero as turn-off. Make it terminal:
|
||||
# color is meaningless while off and must not become a later turn-on.
|
||||
service_data = {
|
||||
key: service_data[key]
|
||||
for key in (ATTR_ENTITY_ID, ATTR_BRIGHTNESS, ATTR_TRANSITION)
|
||||
if key in service_data
|
||||
}
|
||||
service_datas = _split_service_call_data(service_data) if split else [service_data]
|
||||
|
||||
service_datas_length = len(service_datas)
|
||||
|
|
|
|||
|
|
@ -117,7 +117,8 @@ DOCS[CONF_SEPARATE_TURN_ON_COMMANDS] = (
|
|||
|
||||
CONF_SLEEP_BRIGHTNESS, DEFAULT_SLEEP_BRIGHTNESS = "sleep_brightness", 1
|
||||
DOCS[CONF_SLEEP_BRIGHTNESS] = (
|
||||
"Brightness percentage of lights in sleep mode. Set to 0 to prevent lights from turning on. 😴"
|
||||
"Brightness percentage of lights in sleep mode. Set to 0 to turn lights off "
|
||||
"when brightness adaptation runs in sleep mode. 😴"
|
||||
)
|
||||
|
||||
CONF_SLEEP_COLOR_TEMP, DEFAULT_SLEEP_COLOR_TEMP = "sleep_color_temp", 1000
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ change_switch_settings:
|
|||
selector:
|
||||
boolean: null
|
||||
sleep_brightness:
|
||||
description: Brightness percentage of lights in sleep mode. Set to 0 to prevent lights from turning on. 😴
|
||||
description: Brightness percentage of lights in sleep mode. Set to 0 to turn lights off when brightness adaptation runs in sleep mode. 😴
|
||||
required: false
|
||||
example: 1
|
||||
selector:
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
"data_description": {
|
||||
"interval": "Frequency to adapt the lights, in seconds. 🔄",
|
||||
"transition": "Duration of transition when lights change, in seconds. 🕑",
|
||||
"sleep_brightness": "Brightness percentage of lights in sleep mode. 😴",
|
||||
"sleep_brightness": "Brightness percentage of lights in sleep mode. Set to 0 to turn lights off when brightness adaptation runs in sleep mode. 😴",
|
||||
"sleep_color_temp": "Color temperature in sleep mode (used when `sleep_rgb_or_color_temp` is `color_temp`) in Kelvin. 😴"
|
||||
},
|
||||
"sections": {
|
||||
|
|
@ -219,7 +219,7 @@
|
|||
"name": "send_split_delay"
|
||||
},
|
||||
"sleep_brightness": {
|
||||
"description": "Brightness percentage of lights in sleep mode. 😴",
|
||||
"description": "Brightness percentage of lights in sleep mode. Set to 0 to turn lights off when brightness adaptation runs in sleep mode. 😴",
|
||||
"name": "sleep_brightness"
|
||||
},
|
||||
"sleep_rgb_or_color_temp": {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
"data_description": {
|
||||
"interval": "Frequency to adapt the lights, in seconds. 🔄",
|
||||
"transition": "Duration of transition when lights change, in seconds. 🕑",
|
||||
"sleep_brightness": "Brightness percentage of lights in sleep mode. 😴",
|
||||
"sleep_brightness": "Brightness percentage of lights in sleep mode. Set to 0 to turn lights off when brightness adaptation runs in sleep mode. 😴",
|
||||
"sleep_color_temp": "Color temperature in sleep mode (used when `sleep_rgb_or_color_temp` is `color_temp`) in Kelvin. 😴"
|
||||
},
|
||||
"sections": {
|
||||
|
|
@ -220,7 +220,7 @@
|
|||
"name": "send_split_delay"
|
||||
},
|
||||
"sleep_brightness": {
|
||||
"description": "Brightness percentage of lights in sleep mode. 😴",
|
||||
"description": "Brightness percentage of lights in sleep mode. Set to 0 to turn lights off when brightness adaptation runs in sleep mode. 😴",
|
||||
"name": "sleep_brightness"
|
||||
},
|
||||
"sleep_rgb_or_color_temp": {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue