mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 22:34:04 +02:00
Merge pull request #239 from MangoScango/delay
Avoid flickering on light turn on with a configurable delay
This commit is contained in:
commit
dd141d2335
4 changed files with 23 additions and 2 deletions
|
|
@ -51,6 +51,7 @@ CONF_MANUAL_CONTROL = "manual_control"
|
|||
SERVICE_APPLY = "apply"
|
||||
CONF_TURN_ON_LIGHTS = "turn_on_lights"
|
||||
|
||||
CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY = "adapt_delay", 0
|
||||
TURNING_OFF_DELAY = 5
|
||||
|
||||
|
||||
|
|
@ -80,6 +81,7 @@ VALIDATION_TUPLES = [
|
|||
(CONF_TAKE_OVER_CONTROL, DEFAULT_TAKE_OVER_CONTROL, bool),
|
||||
(CONF_DETECT_NON_HA_CHANGES, DEFAULT_DETECT_NON_HA_CHANGES, bool),
|
||||
(CONF_SEPARATE_TURN_ON_COMMANDS, DEFAULT_SEPARATE_TURN_ON_COMMANDS, bool),
|
||||
(CONF_ADAPT_DELAY, DEFAULT_ADAPT_DELAY, int_between(0, 10000)),
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,8 @@
|
|||
"sunset_time": "sunset_time, in 'HH:MM:SS' format (if 'None', it uses the actual sunset time at your location)",
|
||||
"take_over_control": "take_over_control, if anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.",
|
||||
"detect_non_ha_changes": "detect_non_ha_changes, detects all >5% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)",
|
||||
"transition": "transition, in seconds"
|
||||
"transition": "transition, in seconds",
|
||||
"adapt_delay": "Wait time between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ from .const import (
|
|||
SUN_EVENT_MIDNIGHT,
|
||||
SUN_EVENT_NOON,
|
||||
TURNING_OFF_DELAY,
|
||||
CONF_ADAPT_DELAY,
|
||||
VALIDATION_TUPLES,
|
||||
replace_none_str,
|
||||
)
|
||||
|
|
@ -566,6 +567,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
self._separate_turn_on_commands = data[CONF_SEPARATE_TURN_ON_COMMANDS]
|
||||
self._take_over_control = data[CONF_TAKE_OVER_CONTROL]
|
||||
self._transition = data[CONF_TRANSITION]
|
||||
self._adapt_delay = data[CONF_ADAPT_DELAY]
|
||||
_loc = get_astral_location(self.hass)
|
||||
if isinstance(_loc, tuple):
|
||||
# Astral v2.2
|
||||
|
|
@ -961,6 +963,21 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
"%s: Cancelling adjusting lights for %s", self._name, entity_id
|
||||
)
|
||||
return
|
||||
|
||||
if self._adapt_delay > 0:
|
||||
_LOGGER.debug(
|
||||
"%s: sleep started for '%s' with context.id='%s'",
|
||||
self._name,
|
||||
entity_id,
|
||||
event.context.id,
|
||||
)
|
||||
await asyncio.sleep(self._adapt_delay)
|
||||
_LOGGER.debug(
|
||||
"%s: sleep ended for '%s' with context.id='%s'",
|
||||
self._name,
|
||||
entity_id,
|
||||
event.context.id,
|
||||
)
|
||||
|
||||
await self._update_attrs_and_maybe_adapt_lights(
|
||||
lights=[entity_id],
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@
|
|||
"sunset_time": "sunset_time: Manual override of the sunset time, if 'None', it uses the actual sunrise time at your location (HH:MM:SS)",
|
||||
"take_over_control": "take_over_control: If anything but Adaptive Lighting calls 'light.turn_on' when a light is already on, stop adapting that light until it (or the switch) toggles off -> on.",
|
||||
"detect_non_ha_changes": "detect_non_ha_changes: detects all >10% changes made to the lights (also outside of HA), requires 'take_over_control' to be enabled (calls 'homeassistant.update_entity' every 'interval'!)",
|
||||
"transition": "Transition time when applying a change to the lights (seconds)"
|
||||
"transition": "Transition time when applying a change to the lights (seconds)",
|
||||
"adapt_delay": "Wait time between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue