From 6ebab5de25893764ecbd6b285956b9c8078cbb26 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 28 Jul 2018 14:05:04 +0200 Subject: [PATCH] Animation thread wrapped in a try-except to prevent the thread from exiting in case of temporary errors --- platypush/plugins/light/hue/__init__.py | 34 ++++++++++++++----------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/platypush/plugins/light/hue/__init__.py b/platypush/plugins/light/hue/__init__.py index 57688048..a5bd83fc 100644 --- a/platypush/plugins/light/hue/__init__.py +++ b/platypush/plugins/light/hue/__init__.py @@ -502,23 +502,27 @@ class LightHuePlugin(LightPlugin): (duration and time.time() - animation_start_time > duration): break - if animation == self.Animation.COLOR_TRANSITION: - for (light, attrs) in lights.items(): - self.logger.info('Setting {} to {}'.format(light, attrs)) - self.bridge.set_light(light, attrs) + try: + if animation == self.Animation.COLOR_TRANSITION: + for (light, attrs) in lights.items(): + self.logger.info('Setting {} to {}'.format(light, attrs)) + self.bridge.set_light(light, attrs) + stop_animation = _should_stop() + if stop_animation: break + elif animation == self.Animation.BLINK: + conf = lights[list(lights.keys())[0]] + self.logger.info('Setting lights to {}'.format(conf)) + + if groups: + self.bridge.set_group([g.name for f in groups], conf) + else: + self.bridge.set_light(lights.keys(), conf) + stop_animation = _should_stop() if stop_animation: break - elif animation == self.Animation.BLINK: - conf = lights[list(lights.keys())[0]] - self.logger.info('Setting lights to {}'.format(conf)) - - if groups: - self.bridge.set_group([g.name for f in groups], conf) - else: - self.bridge.set_light(lights.keys(), conf) - - stop_animation = _should_stop() - if stop_animation: break + except Exception as e: + self.logger.warning(e) + time.sleep(2) lights = _next_light_attrs(lights)