mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-11 14:24:03 +02:00
Prevent light.turn_on of light that was just turned off (#727)
Closes #726
This commit is contained in:
parent
b06d38eb24
commit
597e050ab2
1 changed files with 16 additions and 1 deletions
|
|
@ -1120,6 +1120,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
self.manager.reset(*self.lights)
|
||||
|
||||
async def _async_update_at_interval_action(self, now=None) -> None: # noqa: ARG002
|
||||
"""Update the attributes and maybe adapt the lights."""
|
||||
await self._update_attrs_and_maybe_adapt_lights(
|
||||
context=self.create_context("interval"),
|
||||
transition=self._transition,
|
||||
|
|
@ -1331,7 +1332,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
data,
|
||||
)
|
||||
|
||||
async def _update_attrs_and_maybe_adapt_lights(
|
||||
async def _update_attrs_and_maybe_adapt_lights( # noqa: PLR0912
|
||||
self,
|
||||
*,
|
||||
context: Context,
|
||||
|
|
@ -1379,6 +1380,20 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
self._name,
|
||||
light,
|
||||
)
|
||||
elif (
|
||||
# This is to prevent lights immediately turning on after
|
||||
# being turned off in 'interval' update, see #726
|
||||
not self._detect_non_ha_changes
|
||||
and is_our_context(context, "interval")
|
||||
and (turn_on := self.manager.turn_on_event.get(light))
|
||||
and (turn_off := self.manager.turn_off_event.get(light))
|
||||
and turn_off.time_fired > turn_on.time_fired
|
||||
):
|
||||
_LOGGER.debug(
|
||||
"%s: Light '%s' was turned just turned off",
|
||||
self._name,
|
||||
light,
|
||||
)
|
||||
else:
|
||||
filtered_lights.append(light)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue