Only cancel ongoing adaptation calls if still running (#668)

This commit is contained in:
Bas Nijholt 2023-07-27 17:34:56 -07:00 committed by GitHub
commit f699486fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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'",