From da6cdb74f5f5e80de4ab51e6f398390ea6a12dc1 Mon Sep 17 00:00:00 2001 From: Eric Date: Sat, 13 Jun 2020 04:37:21 +0100 Subject: [PATCH] play nice with effects that may interrupt progress --- octoprint_rgb_status/__init__.py | 12 ++++++++++-- octoprint_rgb_status/basic_effects.py | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/octoprint_rgb_status/__init__.py b/octoprint_rgb_status/__init__.py index 6b60c72..7f14199 100644 --- a/octoprint_rgb_status/__init__.py +++ b/octoprint_rgb_status/__init__.py @@ -341,11 +341,19 @@ def on_event(self, event, payload): self.run_disconnected_effect() def on_print_progress(self, storage, path, progress): - if progress == 100 and hasattr(self, '_effect') and self._effect.is_alive(): + if progress == 100 and hasattr(self, '_effect') and self._effect.is_alive() and self._effect.name != 'Progress': self._logger.info('Progress was set to 100, but the idle effect was already running. Ignoring progress update') + return if self.strip is not None and self._settings.get_boolean(['show_progress']): self._logger.info('Updating Progress LEDs: ' + str(progress)) - if hasattr(self, '_queue'): + if self._effect.name != 'Progress': + self.run_effect( + progress_effect, + hex_to_rgb(self._settings.get(['progress_base_color'])), + progress=progress, + progress_color=hex_to_rgb(self._settings.get(['progress_color'])), + ) + elif hasattr(self, '_queue'): self._queue.put(progress) elif self.strip is None: self._logger.error('Error setting progress: The strip object does not exist. Did it fail to initialize?') diff --git a/octoprint_rgb_status/basic_effects.py b/octoprint_rgb_status/basic_effects.py index 914efaf..9f1aaf9 100644 --- a/octoprint_rgb_status/basic_effects.py +++ b/octoprint_rgb_status/basic_effects.py @@ -17,7 +17,7 @@ def run_effect(effect, lock, queue, settings, color, delay, shutdown_event, reve message = queue.get() if message == 'KILL': break - else: + elif 'progress' in kwargs: kwargs['progress'] = int(message) effect(strip, color, queue, delay, reverse=reverse, **kwargs) finally: