This commit is contained in:
Benjamin Auquite 2023-04-05 22:15:00 -05:00
commit b8009e0a1a
2 changed files with 21 additions and 5 deletions

View file

@ -1035,6 +1035,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
prefer_rgb_color: bool | None = None,
force: bool = False,
context: Context | None = None,
debug_force_transition: bool = False,
) -> None:
lock = self._locks.get(light)
if lock is not None and lock.locked():
@ -1053,7 +1054,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
prefer_rgb_color = self._prefer_rgb_color
# Check transition == 0 to fix #378
if "transition" in features and transition > 0:
if transition > 0:
service_data[ATTR_TRANSITION] = transition
# The switch might be off and not have _settings set.
@ -1102,7 +1103,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
return
# See #80. Doesn't check if transitions differ but it does the job.
last_service_data = self.turn_on_off_listener.last_service_data
if last_service_data.get(light) == service_data:
if not force and last_service_data.get(light) == service_data:
_LOGGER.debug(
"%s: Cancelling adapt to light %s, there's no new values to set (context.id='%s')",
self._name,
@ -1149,6 +1150,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
transition: int | None = None,
force: bool = False,
context: Context | None = None,
debug_force_transition: bool = False,
) -> None:
assert context is not None
_LOGGER.debug(
@ -1187,7 +1189,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
if not filtered_lights:
return
await self._adapt_lights(filtered_lights, transition, force, context)
await self._adapt_lights(
filtered_lights, transition, force, context, debug_force_transition
)
async def _adapt_lights(
self,
@ -1195,6 +1199,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
transition: int | None,
force: bool,
context: Context | None,
debug_force_transition: bool = False,
) -> None:
assert context is not None
_LOGGER.debug(

View file

@ -641,7 +641,7 @@ async def test_auto_reset_manual_control(hass):
async def test_transition_timers(hass):
switch, (light, *_) = await setup_lights_and_switch(hass)
async def update(force):
async def update(force=False):
await switch._update_attrs_and_maybe_adapt_lights(
transition=1,
context=switch.create_context("test"),
@ -649,9 +649,20 @@ async def test_transition_timers(hass):
)
await hass.async_block_till_done()
async def turn_light(state, **kwargs):
await hass.services.async_call(
LIGHT_DOMAIN,
SERVICE_TURN_ON if state else SERVICE_TURN_OFF,
{ATTR_ENTITY_ID: light.entity_id, **kwargs},
blocking=True,
)
await hass.async_block_till_done()
_LOGGER.debug(
"Turn light %s to state %s, to %s", light.entity_id, state, kwargs
)
_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)