mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-15 00:04:05 +02:00
Merge f73032c045 into b730c7cc90
This commit is contained in:
commit
98d6b65002
2 changed files with 52 additions and 0 deletions
|
|
@ -33,6 +33,18 @@ DOCS[CONF_DETECT_NON_HA_CHANGES] = (
|
|||
"Requires `take_over_control`. 🕵️"
|
||||
)
|
||||
|
||||
(
|
||||
CONF_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA,
|
||||
DEFAULT_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA,
|
||||
) = (
|
||||
"ignore_turnon_with_custom_data",
|
||||
False,
|
||||
)
|
||||
DOCS[CONF_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA] = (
|
||||
"Ignores any lights turned off -> on with custom brightness/color data."
|
||||
" Only a few lights are supported at this time."
|
||||
)
|
||||
|
||||
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, DEFAULT_INCLUDE_CONFIG_IN_ATTRIBUTES = (
|
||||
"include_config_in_attributes",
|
||||
False,
|
||||
|
|
@ -226,6 +238,11 @@ def int_between(min_int, max_int):
|
|||
VALIDATION_TUPLES = [
|
||||
(CONF_LIGHTS, DEFAULT_LIGHTS, cv.entity_ids),
|
||||
(CONF_PREFER_RGB_COLOR, DEFAULT_PREFER_RGB_COLOR, bool),
|
||||
(
|
||||
CONF_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA,
|
||||
DEFAULT_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA,
|
||||
bool,
|
||||
),
|
||||
(CONF_INCLUDE_CONFIG_IN_ATTRIBUTES, DEFAULT_INCLUDE_CONFIG_IN_ATTRIBUTES, bool),
|
||||
(CONF_INITIAL_TRANSITION, DEFAULT_INITIAL_TRANSITION, VALID_TRANSITION),
|
||||
(CONF_SLEEP_TRANSITION, DEFAULT_SLEEP_TRANSITION, VALID_TRANSITION),
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ from .const import (
|
|||
CONF_ADAPT_UNTIL_SLEEP,
|
||||
CONF_AUTORESET_CONTROL,
|
||||
CONF_DETECT_NON_HA_CHANGES,
|
||||
CONF_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA,
|
||||
CONF_INCLUDE_CONFIG_IN_ATTRIBUTES,
|
||||
CONF_INITIAL_TRANSITION,
|
||||
CONF_INTERVAL,
|
||||
|
|
@ -797,6 +798,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
attrdata[k] = v.total_seconds()
|
||||
self._config.update(attrdata)
|
||||
|
||||
self._ignore_light_turnon_with_custom_data = data[
|
||||
CONF_IGNORE_LIGHT_TURNON_WITH_CUSTOM_DATA
|
||||
]
|
||||
self._initial_transition = data[CONF_INITIAL_TRANSITION]
|
||||
self._sleep_transition = data[CONF_SLEEP_TRANSITION]
|
||||
self._only_once = data[CONF_ONLY_ONCE]
|
||||
|
|
@ -1671,6 +1675,7 @@ class TurnOnOffListener:
|
|||
entity_ids,
|
||||
event.context.id,
|
||||
)
|
||||
|
||||
for eid in entity_ids:
|
||||
task = self.sleep_tasks.get(eid)
|
||||
if task is not None:
|
||||
|
|
@ -1685,6 +1690,36 @@ class TurnOnOffListener:
|
|||
# Restart the auto reset timer
|
||||
timer.start()
|
||||
|
||||
# Do not adapt any lights turned on with custom brightness/color_temp/rgb_color
|
||||
# Probably doesn't work for most lights.
|
||||
# Check if the option is enabled first.
|
||||
switches = _get_switches_with_lights(self.hass, entity_ids)
|
||||
found = False
|
||||
for switch in switches:
|
||||
if switch._ignore_light_turnon_with_custom_data:
|
||||
found = True
|
||||
# Option not enabled on any of the light's switches.
|
||||
if not found:
|
||||
return
|
||||
# Check for custom data in service data.
|
||||
if (
|
||||
ATTR_COLOR_TEMP_KELVIN in service_data
|
||||
or ATTR_RGB_COLOR in service_data
|
||||
or ATTR_BRIGHTNESS in service_data
|
||||
or ATTR_XY_COLOR in service_data
|
||||
or ATTR_HS_COLOR in service_data
|
||||
or "color_temp" in service_data
|
||||
):
|
||||
_LOGGER.info(
|
||||
"%s: Light %s was turned on with custom settings."
|
||||
"Setting as manually controlled.",
|
||||
self._name,
|
||||
entity_id,
|
||||
)
|
||||
for eid in entity_ids:
|
||||
self.mark_as_manual_control(eid)
|
||||
_fire_manual_control_event(switch, eid, event.context.id)
|
||||
|
||||
async def state_changed_event_listener(self, event: Event) -> None:
|
||||
"""Track 'state_changed' events."""
|
||||
entity_id = event.data.get(ATTR_ENTITY_ID, "")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue