Lazy inizialitation for the Redis object in light.hue to prevent race conditions on start/stop animation
This commit is contained in:
parent
122978c6f0
commit
c7decd81f2
1 changed files with 11 additions and 6 deletions
|
@ -575,7 +575,8 @@ class LightHuePlugin(LightPlugin):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.animation_thread and self.animation_thread.is_alive():
|
if self.animation_thread and self.animation_thread.is_alive():
|
||||||
self.redis.rpush(self.ANIMATION_CTRL_QUEUE_NAME, 'STOP')
|
redis = self._get_redis()
|
||||||
|
redis.rpush(self.ANIMATION_CTRL_QUEUE_NAME, 'STOP')
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def animate(self, animation, duration=None,
|
def animate(self, animation, duration=None,
|
||||||
|
@ -659,7 +660,8 @@ class LightHuePlugin(LightPlugin):
|
||||||
|
|
||||||
def _should_stop():
|
def _should_stop():
|
||||||
try:
|
try:
|
||||||
self.redis.blpop(self.ANIMATION_CTRL_QUEUE_NAME)
|
redis = self._get_redis()
|
||||||
|
redis.blpop(self.ANIMATION_CTRL_QUEUE_NAME)
|
||||||
return True
|
return True
|
||||||
except QueueTimeoutError:
|
except QueueTimeoutError:
|
||||||
return False
|
return False
|
||||||
|
@ -707,10 +709,6 @@ class LightHuePlugin(LightPlugin):
|
||||||
self.animation_thread = None
|
self.animation_thread = None
|
||||||
self.redis = None
|
self.redis = None
|
||||||
|
|
||||||
redis_args = get_backend('redis').redis_args
|
|
||||||
redis_args['socket_timeout'] = transition_seconds
|
|
||||||
self.redis = Redis(**redis_args)
|
|
||||||
|
|
||||||
if groups:
|
if groups:
|
||||||
groups = [g for g in self.bridge.groups if g.name in groups]
|
groups = [g for g in self.bridge.groups if g.name in groups]
|
||||||
lights = lights or []
|
lights = lights or []
|
||||||
|
@ -725,6 +723,13 @@ class LightHuePlugin(LightPlugin):
|
||||||
args=(lights,))
|
args=(lights,))
|
||||||
self.animation_thread.start()
|
self.animation_thread.start()
|
||||||
|
|
||||||
|
def _get_redis(self):
|
||||||
|
if not self.redis:
|
||||||
|
redis_args = get_backend('redis').redis_args
|
||||||
|
redis_args['socket_timeout'] = transition_seconds
|
||||||
|
self.redis = Redis(**redis_args)
|
||||||
|
return self.redis
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue