From e0364b13cb0799046bc7f7725d721783cae59c4f Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 31 Jul 2023 18:27:31 -0700 Subject: [PATCH] cancel early --- custom_components/adaptive_lighting/switch.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 37fcf8f2..b4da4622 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -2353,13 +2353,16 @@ class AdaptiveLightingManager: entity_id, event.context.id, ) - # Skip resetting here because `_service_interceptor_turn_on_handler` - # ran *just* before this and already reset the light and populated - # `self.last_service_data` with the new data. + if self.is_proactively_adapting(event.context.id): - _LOGGER.debug("We should cancel here?") - else: - self.reset(entity_id, reset_manual_control=False) + _LOGGER.debug( + "Skipping reactive adaptation of light %s with context.id='%s'", + entity_id, + event.context.id, + ) + return + + self.reset(entity_id, reset_manual_control=False) lock = self.turn_off_locks.setdefault(entity_id, asyncio.Lock()) async with lock: if await self.just_turned_off(entity_id):