mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
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.
This commit is contained in:
parent
5fd9220812
commit
d978d58436
@ -642,6 +642,18 @@ class LIFXStrip(LIFXColor):
|
|||||||
bulb = self.device
|
bulb = self.device
|
||||||
num_zones = len(bulb.color_zones)
|
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
|
# Zone brightness is not reported when powered off
|
||||||
if not self.is_on and hsbk[2] is None:
|
if not self.is_on and hsbk[2] is None:
|
||||||
yield from self.set_power(ack, True)
|
yield from self.set_power(ack, True)
|
||||||
@ -650,12 +662,6 @@ class LIFXStrip(LIFXColor):
|
|||||||
yield from self.set_power(ack, False)
|
yield from self.set_power(ack, False)
|
||||||
yield from asyncio.sleep(0.3)
|
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
|
# Send new color to each zone
|
||||||
for index, zone in enumerate(zones):
|
for index, zone in enumerate(zones):
|
||||||
zone_hsbk = merge_hsbk(bulb.color_zones[zone], hsbk)
|
zone_hsbk = merge_hsbk(bulb.color_zones[zone], hsbk)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user