def zone_msgs(self, overrides): power_message = self.power_message(overrides) if power_message: yield power_message colors = self.colors_from_hsbks(self.zones, overrides) duration = self.determine_duration(overrides) start = 0 color = None i = -1 while i < len(colors) - 1: i += 1 if color is None: color = colors[i] continue if colors[i] != color: yield MultiZoneMessages.SetColorZones( start_index=start, end_index=i - 1, **color, duration=duration, res_required=False, ) color = colors[i] start = i color = colors[i] yield MultiZoneMessages.SetColorZones(start_index=start, end_index=i, **color, duration=duration, res_required=False)
async def apply_zone(applier, target, afr, serial, theme, overrides): length = None msg = MultiZoneMessages.GetColorZones(start_index=0, end_index=255) async for pkt, _, _ in target.script(msg).run_with(serial, afr): if pkt | MultiZoneMessages.StateMultiZone: length = pkt.zones_count if length is None: log.warning( hp.lc("Couldn't work out how many zones the light had", serial=serial)) return messages = [] for (start_index, end_index), hsbk in applier(length).apply_theme(theme): messages.append( MultiZoneMessages.SetColorZones(start_index=start_index, end_index=end_index, hue=hsbk.hue, saturation=hsbk.saturation, brightness=hsbk.brightness, kelvin=hsbk.kelvin, duration=overrides.get( "duration", 1), res_required=False, ack_required=True)) set_power = LightMessages.SetLightPower(level=65535, duration=overrides.get( "duration", 1)) pipeline = Pipeline(*messages, spread=0.005) await target.script([set_power, pipeline]).run_with_all(serial, afr)
def setter(h, s, b, k, **kwargs): return MultiZoneMessages.SetColorZones( hue=h, saturation=s, brightness=b, kelvin=k, res_required=False, **kwargs, )
def make_hsbk_old_messages(self, zone_index, colors, duration): set_color_old = [] end = zone_index start = zone_index current = None for i, color in enumerate(colors): i = i + zone_index if current is None: current = color continue if current != color: set_color_old.append( MultiZoneMessages.SetColorZones( start_index=start, end_index=end, duration=duration, ack_required=True, res_required=False, **current, )) start = i current = color end = i if not set_color_old or set_color_old[-1].end_index != i: set_color_old.append( MultiZoneMessages.SetColorZones( start_index=start, end_index=end, duration=duration, ack_required=True, res_required=False, **current, )) return set_color_old
def make_old_messages(self): if not self.colors: return end = self.zone_index start = self.zone_index current = Empty sections = [] for i, color in enumerate(self.colors): i = i + self.zone_index if current is Empty: current = color continue if current != color: sections.append([start, end, current]) start = i start = i current = color end = i if current is not Empty and (not sections or sections[-1][1] != i): sections.append([start, end, current]) msgs = [] for start, end, color in sections: h, s, b, k = color msgs.append( MultiZoneMessages.SetColorZones( start_index=start, end_index=end, duration=self.duration, ack_required=True, res_required=False, target=self.serial, hue=h, saturation=s, brightness=b, kelvin=k, )) return msgs
assert "zones" not in device.attrs await device.assertResponse(MultiZoneMessages.GetMultiZoneEffect(), []) await device.assertResponse( MultiZoneMessages.SetMultiZoneEffect.empty_normalise( type=MultiZoneEffectType.MOVE, parameters={} ), [], ) await device.assertResponse( MultiZoneMessages.GetColorZones(start_index=0, end_index=255), [] ) await device.assertResponse( MultiZoneMessages.SetColorZones( start_index=0, end_index=1, hue=0, saturation=1, brightness=1, kelvin=3500 ), [], ) await device.assertResponse(MultiZoneMessages.GetExtendedColorZones(), []) await device.assertResponse( MultiZoneMessages.SetExtendedColorZones(colors=[chp.Color(0, 0, 0, 0)]), [] ) async it "doesn't respond to extended multizone if we aren't extended multizone": cases = [ (Products.LCM1_Z, chp.Firmware(0, 0, 0), [chp.Color(0, 0, 0, 0)]), (Products.LCM2_Z, chp.Firmware(0, 0, 0), [chp.Color(0, 0, 0, 0)]), ]