fix: make zero brightness adaptation terminal

This commit is contained in:
Bas Nijholt 2026-09-06 09:12:31 -07:00
commit c373e86043
9 changed files with 333 additions and 8 deletions

View file

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

View file

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

View file

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

View file

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

View file

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