add transition_timer test and debug

This commit is contained in:
Benjamin Auquite 2023-04-05 21:31:28 -05:00
commit 4faa39a99b
2 changed files with 33 additions and 6 deletions

View file

@ -1167,14 +1167,22 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
if lights is None:
lights = self._lights
if not force and self._only_once:
return
filtered_lights = []
for light in lights:
# Don't adapt lights that haven't finished prior transitions.
if force or not self.turn_on_off_listener.transition_timers.get(light):
if not force:
if self._only_once:
return
for light in lights:
# Don't adapt lights that haven't finished prior transitions.
if self.turn_on_off_listener.transition_timers.get(light):
_LOGGER.debug(
"%s: Light '%s' is still transitioning for %s more seconds",
self._name,
light,
)
continue
filtered_lights.append(light)
else:
filtered_lights = lights
if not filtered_lights:
return

View file

@ -638,6 +638,25 @@ async def test_auto_reset_manual_control(hass):
assert not manual_control[light.entity_id]
async def test_transition_timers(hass):
switch, (light, *_) = await setup_lights_and_switch()
async def update(force):
await switch._update_attrs_and_maybe_adapt_lights(
transition=1,
context=switch.create_context("test"),
force=force,
)
await hass.async_block_till_done()
_LOGGER.debug("Start test of transition timers")
await update(True)
await asyncio.sleep(0.5)
assert switch.turn_on_off_listener.transition_timers.get(light)
await asyncio.sleep(2)
assert not switch.turn_on_off_listener.transition_timers.get(light)
async def test_apply_service(hass):
"""Test adaptive_lighting.apply service."""
switch, (_, _, light) = await setup_lights_and_switch(hass)