From 777d883733d16088060b8008646b142a07ba46cc Mon Sep 17 00:00:00 2001 From: Halvard <51741357+Samdal@users.noreply.github.com> Date: Fri, 29 Jul 2022 20:19:59 +0200 Subject: [PATCH 1/2] Fix direct fade not stopping running corutine The direct fade class does not stop running corutines when a light update that is able to run in a single `set_brightness_and_fade` call is executed. This causes "race" conditions, ending up with unpredictable and wrong behavior. I've only tested it on my own machine and it works just like the mpf monitor suggests (which was not true previously). --- mpf/platforms/interfaces/light_platform_interface.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mpf/platforms/interfaces/light_platform_interface.py b/mpf/platforms/interfaces/light_platform_interface.py index db0ec4ed5..efc4812f0 100644 --- a/mpf/platforms/interfaces/light_platform_interface.py +++ b/mpf/platforms/interfaces/light_platform_interface.py @@ -95,6 +95,8 @@ def set_fade(self, start_brightness, start_time, target_brightness, target_time) self.task = self.loop.create_task(self._fade(start_brightness, start_time, target_brightness, target_time)) self.task.add_done_callback(Util.raise_exceptions) else: + if self.task: + self.task.cancel() self.set_brightness_and_fade(target_brightness, max(fade_ms, 0)) async def _fade(self, start_brightness, start_time, target_brightness, target_time): From 3d4c67ef970069afc7a0549606396bddef978b09 Mon Sep 17 00:00:00 2001 From: Samdal Date: Sat, 30 Jul 2022 09:09:19 +0200 Subject: [PATCH 2/2] set task to None to prevent double cancel --- mpf/platforms/interfaces/light_platform_interface.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mpf/platforms/interfaces/light_platform_interface.py b/mpf/platforms/interfaces/light_platform_interface.py index efc4812f0..58e8a690a 100644 --- a/mpf/platforms/interfaces/light_platform_interface.py +++ b/mpf/platforms/interfaces/light_platform_interface.py @@ -97,6 +97,7 @@ def set_fade(self, start_brightness, start_time, target_brightness, target_time) else: if self.task: self.task.cancel() + self.task = None self.set_brightness_and_fade(target_brightness, max(fade_ms, 0)) async def _fade(self, start_brightness, start_time, target_brightness, target_time):