From d978d584360ce3d2b89cc67f988cc00473adeeb3 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Thu, 21 Sep 2017 23:32:31 +0200 Subject: [PATCH] LIFX: improve performance of setting multi-zone lights to a single color (#9526) With this optimization we can send a single UDP packet to the light rather than one packet per zone (up to 80 packets for LIFX Z). This removes a potential multi-second latency on the frontend color picker. --- homeassistant/components/light/lifx.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/light/lifx.py b/homeassistant/components/light/lifx.py index 93412710987..ad2cf204463 100644 --- a/homeassistant/components/light/lifx.py +++ b/homeassistant/components/light/lifx.py @@ -642,6 +642,18 @@ class LIFXStrip(LIFXColor): bulb = self.device num_zones = len(bulb.color_zones) + zones = kwargs.get(ATTR_ZONES) + if zones is None: + # Fast track: setting all zones to the same brightness and color + # can be treated as a single-zone bulb. + if hsbk[2] is not None and hsbk[3] is not None: + yield from super().set_color(ack, hsbk, kwargs, duration) + return + + zones = list(range(0, num_zones)) + else: + zones = list(filter(lambda x: x < num_zones, set(zones))) + # Zone brightness is not reported when powered off if not self.is_on and hsbk[2] is None: yield from self.set_power(ack, True) @@ -650,12 +662,6 @@ class LIFXStrip(LIFXColor): yield from self.set_power(ack, False) yield from asyncio.sleep(0.3) - zones = kwargs.get(ATTR_ZONES, None) - if zones is None: - zones = list(range(0, num_zones)) - else: - zones = list(filter(lambda x: x < num_zones, set(zones))) - # Send new color to each zone for index, zone in enumerate(zones): zone_hsbk = merge_hsbk(bulb.color_zones[zone], hsbk)