From 99e34539b9dd08291033228e4405b91676356065 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Tue, 2 May 2017 23:30:07 +0200 Subject: [PATCH] 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. --- .../components/light/lifx/effects.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/light/lifx/effects.py b/homeassistant/components/light/lifx/effects.py index 2c054d49e1a..ae9bd626fca 100644 --- a/homeassistant/components/light/lifx/effects.py +++ b/homeassistant/components/light/lifx/effects.py @@ -196,18 +196,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 None