async def execute(self): fltr = chp.filter_from_matcher(self.matcher, self.refresh) details = await self.finder.info_for(filtr=fltr) msgs = [] for serial, info in details.items(): msgs.append(DeviceMessages.GetPower(target=serial)) if "multizone" in info["cap"]: msgs.append( MultiZoneMessages.GetColorZones(start_index=0, end_index=255, target=serial) ) elif "chain" in info["cap"]: msgs.append( TileMessages.Get64(tile_index=0, length=5, x=0, y=0, width=8, target=serial) ) else: msgs.append(LightMessages.GetColor(target=serial)) state = defaultdict(dict) afr = await self.finder.args_for_run() async for pkt, _, _ in self.target.script(msgs).run_with( None, afr, multiple_replies=True, first_wait=0.5 ): if pkt | DeviceMessages.StatePower: state[pkt.serial]["power"] = pkt.level != 0 elif pkt | LightMessages.LightState: hsbk = f"kelvin:{pkt.kelvin} saturation:{pkt.saturation} brightness:{pkt.brightness} hue:{pkt.hue}" state[pkt.serial]["color"] = hsbk elif pkt | MultiZoneMessages.StateMultiZone: if "zones" not in state[pkt.serial]: state[pkt.serial]["zones"] = {} for i, zi in enumerate(range(pkt.zone_index, pkt.zone_index + 8)): c = pkt.colors[i] state[pkt.serial]["zones"][zi] = [c.hue, c.saturation, c.brightness, c.kelvin] elif pkt | TileMessages.State64: if "chain" not in state[pkt.serial]: state[pkt.serial]["chain"] = {} colors = [[c.hue, c.saturation, c.brightness, c.kelvin] for c in pkt.colors] state[pkt.serial]["chain"][pkt.tile_index] = colors scene = [] for serial, info in sorted(state.items()): if "zones" in info: info["zones"] = [hsbk for _, hsbk in sorted(info["zones"].items())] if "chain" in info: info["chain"] = [hsbks for _, hsbks in sorted(info["chain"].items())] scene.append({"matcher": {"serial": serial}, **info}) if self.just_return: return scene args = { "uuid": self.uuid, "scene": scene, "label": self.label, "description": self.description, } return await self.executor.execute(self.path, {"command": "scene_change", "args": args})
def messages(self): if not self.is_light: return Skip if self.zones is Zones.SINGLE: return [LightMessages.GetColor()] elif self.zones is Zones.MATRIX: return [ TileMessages.Get64( x=0, y=0, tile_index=0, length=255, width=self.deps["chain"]["width"] ) ] else: return []
got = await self.gather(sender, serials, "colors") assert got[switch.serial][1]["colors"] is Skip assert got[light1.serial][1]["colors"] == tile_expected assert got[light2.serial][1]["colors"] == [[hp.Color(100, 0.5, 0.8, 2500)]] assert got[striplcm1.serial][1]["colors"] == [expectedlcm1] assert got[striplcm2extended.serial][1]["colors"] == [expectedlcm2] expected = { clean: [], switch: [DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion()], light1: [ DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion(), TileMessages.GetDeviceChain(), TileMessages.Get64(length=255, tile_index=0, width=8, x=0, y=0), ], light2: [ DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion(), LightMessages.GetColor(), ], striplcm1: [ DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion(), MultiZoneMessages.GetColorZones(start_index=0, end_index=255), ], striplcm2noextended: [], striplcm2extended: [ DeviceMessages.GetHostFirmware(), DeviceMessages.GetVersion(),