Skip to content

Commit 597e050

Browse files
authored
Prevent light.turn_on of light that was just turned off (#727)
Closes #726
1 parent b06d38e commit 597e050

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

custom_components/adaptive_lighting/switch.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ async def async_turn_off(self, **kwargs) -> None: # noqa: ARG002
11201120
self.manager.reset(*self.lights)
11211121

11221122
async def _async_update_at_interval_action(self, now=None) -> None: # noqa: ARG002
1123+
"""Update the attributes and maybe adapt the lights."""
11231124
await self._update_attrs_and_maybe_adapt_lights(
11241125
context=self.create_context("interval"),
11251126
transition=self._transition,
@@ -1331,7 +1332,7 @@ async def execute_cancellable_adaptation_calls(
13311332
data,
13321333
)
13331334

1334-
async def _update_attrs_and_maybe_adapt_lights(
1335+
async def _update_attrs_and_maybe_adapt_lights( # noqa: PLR0912
13351336
self,
13361337
*,
13371338
context: Context,
@@ -1379,6 +1380,20 @@ async def _update_attrs_and_maybe_adapt_lights(
13791380
self._name,
13801381
light,
13811382
)
1383+
elif (
1384+
# This is to prevent lights immediately turning on after
1385+
# being turned off in 'interval' update, see #726
1386+
not self._detect_non_ha_changes
1387+
and is_our_context(context, "interval")
1388+
and (turn_on := self.manager.turn_on_event.get(light))
1389+
and (turn_off := self.manager.turn_off_event.get(light))
1390+
and turn_off.time_fired > turn_on.time_fired
1391+
):
1392+
_LOGGER.debug(
1393+
"%s: Light '%s' was turned just turned off",
1394+
self._name,
1395+
light,
1396+
)
13821397
else:
13831398
filtered_lights.append(light)
13841399

0 commit comments

Comments
 (0)