From f699486fd0752c99df4abb551fa77a65e918bb1f Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Thu, 27 Jul 2023 17:34:56 -0700 Subject: [PATCH] Only cancel ongoing adaptation calls if still running (#668) --- custom_components/adaptive_lighting/switch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 72b53635..24304730 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -2151,7 +2151,11 @@ class AdaptiveLightingManager: """Cancel ongoing adaptation service calls for a specific light entity.""" brightness_task = self.adaptation_tasks_brightness.get(light_id) color_task = self.adaptation_tasks_color.get(light_id) - if which in ("both", "brightness") and brightness_task is not None: + if ( + which in ("both", "brightness") + and brightness_task is not None + and not brightness_task.done() + ): _LOGGER.debug( "Cancelled ongoing brightness adaptation calls (%s) for '%s'", brightness_task, @@ -2162,6 +2166,7 @@ class AdaptiveLightingManager: which in ("both", "color") and color_task is not None and color_task is not brightness_task + and not color_task.done() ): _LOGGER.debug( "Cancelled ongoing color adaptation calls (%s) for '%s'",