LIFX: fix color restore after running effects

State restoration takes up to a second because bulbs can be slow to react.
During this time an effect could keep running, overwriting the state that we
were trying to restore.

Now the effect forgets the light immediately and it thus avoids further
changes while the restored state settles.
This commit is contained in:
Anders Melchiorsen 2017-05-02 23:30:07 +02:00 committed by Paulus Schoutsen
parent 1c5eb88368
commit 71f9507df7

View File

@ -198,18 +198,19 @@ class LIFXEffect(object):
@asyncio.coroutine
def async_restore(self, light):
"""Restore to the original state (if we are still running)."""
if light.effect_data:
if light.effect_data.effect == self:
if light.device and not light.effect_data.power:
light.device.set_power(False)
yield from asyncio.sleep(0.5)
if light.device:
light.device.set_color(light.effect_data.color)
yield from asyncio.sleep(0.5)
light.effect_data = None
yield from light.refresh_state()
if light in self.lights:
self.lights.remove(light)
if light.effect_data and light.effect_data.effect == self:
if light.device and not light.effect_data.power:
light.device.set_power(False)
yield from asyncio.sleep(0.5)
if light.device:
light.device.set_color(light.effect_data.color)
yield from asyncio.sleep(0.5)
light.effect_data = None
yield from light.refresh_state()
def from_poweroff_hsbk(self, light, **kwargs):
"""Return the color when starting from a powered off state."""
return [random.randint(0, 65535), 65535, 0, NEUTRAL_WHITE]