Name external turn-on policy after manual-control behavior

This commit is contained in:
Bas Nijholt 2026-09-06 11:56:48 -07:00
commit c88e444529
11 changed files with 57 additions and 47 deletions

View file

@ -100,16 +100,14 @@ DOCS[CONF_ADAPT_ONLY_ON_BARE_TURN_ON] = (
"Needs `take_over_control` enabled. 🕵️"
)
CONF_ADAPT_ONLY_ON_HA_TURN_ON, DEFAULT_ADAPT_ONLY_ON_HA_TURN_ON = (
"adapt_only_on_ha_turn_on",
CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON, DEFAULT_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON = (
"manual_control_on_external_turn_on",
False,
)
DOCS[CONF_ADAPT_ONLY_ON_HA_TURN_ON] = (
"Only adapt an `off` to `on` event when its context exactly matches the latest "
"recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons "
"are marked as manually controlled and left unchanged. This still allows "
"`detect_non_ha_changes` for lights that are already on. Needs `take_over_control` "
"enabled. 🕵️"
DOCS[CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON] = (
"Treat turn-ons without a matching Home Assistant `light.turn_on` context as "
"manual control. Normal manual-control resets apply. Still allows "
"`detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️"
)
CONF_PREFER_RGB_COLOR, DEFAULT_PREFER_RGB_COLOR = "prefer_rgb_color", False
@ -428,7 +426,11 @@ VALIDATION_TUPLES: list[tuple[str, Any, Any]] = [
),
(CONF_ONLY_ONCE, DEFAULT_ONLY_ONCE, bool),
(CONF_ADAPT_ONLY_ON_BARE_TURN_ON, DEFAULT_ADAPT_ONLY_ON_BARE_TURN_ON, bool),
(CONF_ADAPT_ONLY_ON_HA_TURN_ON, DEFAULT_ADAPT_ONLY_ON_HA_TURN_ON, bool),
(
CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON,
DEFAULT_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON,
bool,
),
(
CONF_RESET_MANUAL_CONTROL_ON_SLEEP_MODE_CHANGE,
DEFAULT_RESET_MANUAL_CONTROL_ON_SLEEP_MODE_CHANGE,

View file

@ -238,8 +238,8 @@ change_switch_settings:
example: false
selector:
boolean: null
adapt_only_on_ha_turn_on:
description: Only adapt an `off` to `on` event when its context exactly matches the latest recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons are marked as manually controlled and left unchanged. This still allows `detect_non_ha_changes` for lights that are already on. Needs `take_over_control` enabled. 🕵️
manual_control_on_external_turn_on:
description: Treat turn-ons without a matching Home Assistant `light.turn_on` context as manual control. Normal manual-control resets apply. Still allows `detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️
required: false
example: false
selector:

View file

@ -70,7 +70,7 @@
"autoreset_control_seconds": "autoreset_control_seconds",
"only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄",
"adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene and marks the light as manually controlled. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️",
"adapt_only_on_ha_turn_on": "adapt_only_on_ha_turn_on: Only adapt an `off` to `on` event when its context exactly matches the latest recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons are marked as manually controlled and left unchanged. This still allows `detect_non_ha_changes` for lights that are already on. Needs `take_over_control` enabled. 🕵️",
"manual_control_on_external_turn_on": "manual_control_on_external_turn_on: Treat turn-ons without a matching Home Assistant `light.turn_on` context as manual control. Normal manual-control resets apply. Still allows `detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️",
"reset_manual_control_on_sleep_mode_change": "reset_manual_control_on_sleep_mode_change: Reset manual control when the sleep mode switch is toggled. Set to `false` to preserve manual control across sleep mode changes. 😴",
"separate_turn_on_commands": "separate_turn_on_commands: Use separate `light.turn_on` calls for color and brightness, needed for some light types. 🔀",
"send_split_delay": "send_split_delay",
@ -271,9 +271,9 @@
"description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Note that this calls `homeassistant.update_entity` every `interval`! Disable this feature if you encounter such issues.",
"name": "detect_non_ha_changes"
},
"adapt_only_on_ha_turn_on": {
"description": "Only adapt an `off` to `on` event when its context exactly matches the latest recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons are marked as manually controlled and left unchanged. This still allows `detect_non_ha_changes` for lights that are already on. Needs `take_over_control` enabled. 🕵️",
"name": "adapt_only_on_ha_turn_on"
"manual_control_on_external_turn_on": {
"description": "Treat turn-ons without a matching Home Assistant `light.turn_on` context as manual control. Normal manual-control resets apply. Still allows `detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️",
"name": "manual_control_on_external_turn_on"
},
"transition": {
"description": "Duration of transition when lights change, in seconds. 🕑",

View file

@ -92,7 +92,6 @@ from .const import (
ATTR_ADAPTIVE_LIGHTING_MANAGER,
CONF_ADAPT_DELAY,
CONF_ADAPT_ONLY_ON_BARE_TURN_ON,
CONF_ADAPT_ONLY_ON_HA_TURN_ON,
CONF_ADAPT_UNTIL_SLEEP,
CONF_AUTORESET_CONTROL,
CONF_BRIGHTNESS_MODE,
@ -105,6 +104,7 @@ from .const import (
CONF_INTERVAL,
CONF_LIGHTS,
CONF_MANUAL_CONTROL,
CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON,
CONF_MAX_BRIGHTNESS,
CONF_MAX_COLOR_TEMP,
CONF_MAX_SUNRISE_TIME,
@ -958,11 +958,11 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
if not data[CONF_TAKE_OVER_CONTROL] and (
data[CONF_DETECT_NON_HA_CHANGES]
or data[CONF_ADAPT_ONLY_ON_BARE_TURN_ON]
or data[CONF_ADAPT_ONLY_ON_HA_TURN_ON]
or data[CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON]
):
_LOGGER.warning(
"%s: Config mismatch: `detect_non_ha_changes`, `adapt_only_on_bare_turn_on`, "
"or `adapt_only_on_ha_turn_on` set to `true` requires `take_over_control` to be "
"or `manual_control_on_external_turn_on` set to `true` requires `take_over_control` to be "
"enabled. Adjusting config and continuing setup with `take_over_control: true`.",
self._name,
)
@ -972,7 +972,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
)
self._detect_non_ha_changes = data[CONF_DETECT_NON_HA_CHANGES]
self._adapt_only_on_bare_turn_on = data[CONF_ADAPT_ONLY_ON_BARE_TURN_ON]
self._adapt_only_on_ha_turn_on = data[CONF_ADAPT_ONLY_ON_HA_TURN_ON]
self._manual_control_on_external_turn_on = data[
CONF_MANUAL_CONTROL_ON_EXTERNAL_TURN_ON
]
self._auto_reset_manual_control_time = data[CONF_AUTORESET_CONTROL]
self._reset_manual_control_on_sleep_mode_change = data[
CONF_RESET_MANUAL_CONTROL_ON_SLEEP_MODE_CHANGE
@ -1607,7 +1609,10 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
)
if (
self._take_over_control
and (not self._detect_non_ha_changes or self._adapt_only_on_ha_turn_on)
and (
not self._detect_non_ha_changes
or self._manual_control_on_external_turn_on
)
and not from_turn_on
):
# There is an edge case where 2 switches control the same light, e.g.,
@ -1618,12 +1623,12 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
# `light.turn_on` context for the entity. Hand control over when either:
# - `detect_non_ha_changes` is False (we can't reliably track manual changes
# to already-on lights anyway), or
# - `adapt_only_on_ha_turn_on` is True (the user explicitly wants external
# - `manual_control_on_external_turn_on` is True (the user explicitly wants external
# turn-ons left untouched, even while `detect_non_ha_changes` is enabled).
_LOGGER.debug(
"%s: Ignoring 'off' → 'on' event for '%s' with context.id='%s'"
" because it does not match a tracked 'light.turn_on' context and"
" ('detect_non_ha_changes' is False or 'adapt_only_on_ha_turn_on' is True)",
" ('detect_non_ha_changes' is False or 'manual_control_on_external_turn_on' is True)",
self._name,
entity_id,
event.context.id,

View file

@ -71,7 +71,7 @@
"autoreset_control_seconds": "autoreset_control_seconds",
"only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄",
"adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene and marks the light as manually controlled. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️",
"adapt_only_on_ha_turn_on": "adapt_only_on_ha_turn_on: Only adapt an `off` to `on` event when its context exactly matches the latest recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons are marked as manually controlled and left unchanged. This still allows `detect_non_ha_changes` for lights that are already on. Needs `take_over_control` enabled. 🕵️",
"manual_control_on_external_turn_on": "manual_control_on_external_turn_on: Treat turn-ons without a matching Home Assistant `light.turn_on` context as manual control. Normal manual-control resets apply. Still allows `detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️",
"reset_manual_control_on_sleep_mode_change": "reset_manual_control_on_sleep_mode_change: Reset manual control when the sleep mode switch is toggled. Set to `false` to preserve manual control across sleep mode changes. 😴",
"separate_turn_on_commands": "separate_turn_on_commands: Use separate `light.turn_on` calls for color and brightness, needed for some light types. 🔀",
"send_split_delay": "send_split_delay",
@ -272,9 +272,9 @@
"description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Note that this calls `homeassistant.update_entity` every `interval`! Disable this feature if you encounter such issues.",
"name": "detect_non_ha_changes"
},
"adapt_only_on_ha_turn_on": {
"description": "Only adapt an `off` to `on` event when its context exactly matches the latest recorded Home Assistant `light.turn_on` context for that light. Unmatched turn-ons are marked as manually controlled and left unchanged. This still allows `detect_non_ha_changes` for lights that are already on. Needs `take_over_control` enabled. 🕵️",
"name": "adapt_only_on_ha_turn_on"
"manual_control_on_external_turn_on": {
"description": "Treat turn-ons without a matching Home Assistant `light.turn_on` context as manual control. Normal manual-control resets apply. Still allows `detect_non_ha_changes` for already-on lights. Needs `take_over_control` enabled. 🕵️",
"name": "manual_control_on_external_turn_on"
},
"transition": {
"description": "Duration of transition when lights change, in seconds. 🕑",