def chain_msgs(self, overrides): power_message = self.power_message(overrides) if power_message: yield power_message duration = self.determine_duration(overrides) for i, lst in enumerate(self.chain): colors = self.colors_from_hsbks(lst, overrides) yield TileMessages.Set64( tile_index=i, length=1, x=0, y=0, width=8, duration=duration, colors=colors, res_required=False, )
async def restore(self, serial, initial, target, afr): msgs = [DeviceMessages.SetPower(level=initial["power"])] for i, colors in enumerate(initial["colors"]): msgs.append( TileMessages.Set64( tile_index=i, length=1, width=8, x=0, y=0, colors=colors, res_required=False, ack_required=True, )) def errors(e): log.error(hp.lc("Error restoring tile", serial=serial, error=e)) await target.script(msgs).run_with_all(serial, afr, error_catcher=errors)
def __init__(self): self.targets_cache = LRU(1000) self.source_bits_cache = LRU(10) self.duration_bits_cache = LRU(10) self.cache = ProtocolColor.Meta.cache msg = TileMessages.Set64( source=0, sequence=0, target="d073d5000000", res_required=False, ack_required=True, tile_index=0, length=1, x=0, y=0, width=8, duration=0, colors=[{"hue": 0, "saturation": 0, "brightness": 0, "kelvin": 3500}], ) self.frame_header_start = msg.frame_header.pack()[:-32] self.frame_address_with_acks_middle = msg.frame_address.pack()[64:-8] msg.ack_required = False self.frame_address_without_acks_middle = msg.frame_address.pack()[64:-8] self.protocol_header_packd = msg.protocol_header.pack() # tile_index, width, duration and colors are variable self.payload_middle = msg.payload.pack()[8 : -8 - 32 - (64 * 64)] self.uint8_bits = {val: self.bits(T.Uint8, val) for val in range(256)} self.width_bits = self.uint8_bits self.sequence_bits = self.uint8_bits self.tile_index_bits = self.uint8_bits
async def tile_msgs(self): coords_and_sizes = None async for _, _, info in self.gather(self.make_plans("chain")): reorient = info["reorient"] coords_and_sizes = info["coords_and_sizes"] if not coords_and_sizes: log.warning( hp.lc("Couldn't work out how many zones the device had", serial=self.serial) ) return applied = self.aps["2d"].from_user_coords(coords_and_sizes).apply_theme(self.theme) for i, (hsbks, coords_and_size) in enumerate(zip(applied, coords_and_sizes)): colors = reorient( i, [ { "hue": self.options.overrides.get("hue", hsbk.hue), "saturation": self.options.overrides.get("saturation", hsbk.saturation), "brightness": self.options.overrides.get("brightness", hsbk.brightness), "kelvin": self.options.overrides.get("kelvin", hsbk.kelvin), } for hsbk in hsbks ], ) yield TileMessages.Set64( tile_index=i, length=1, x=0, y=0, width=coords_and_size[1][0], duration=self.options.duration, colors=colors, res_required=False, ack_required=True, )
def setter(**kwargs): return TileMessages.Set64( length=1, x=0, y=0, width=8, res_required=False, **kwargs )
async def highlight(self, serial, tile_index, target, afr, error_catcher=None, message_timeout=3): if serial not in self.serials or self.serials[serial][ "highlightlock"].locked(): return async with self.serials[serial]["highlightlock"]: if serial not in self.serials: return passed = 0 row = -1 pixels = self.serials[serial]["color_pixels"][tile_index] reorient = self.serials[serial]["reorient"] while passed < 2 and not afr.stop_fut.done(): colors = [] for i in range(8): if row < i: start = i * 8 colors.extend(pixels[start:start + 8]) else: colors.extend([{ "hue": 0, "saturation": 0, "brightness": 0, "kelvin": 3500 }] * 8) msg = TileMessages.Set64( tile_index=tile_index, length=1, x=0, y=0, width=8, colors=reorient(tile_index, colors), res_required=False, ack_required=False, ) await target.script(msg).run_with_all(serial, afr, error_catcher=[]) await asyncio.sleep(0.075) if passed == 0: row += 3 if row > 7: passed += 1 else: row -= 3 if row < 0: passed += 1 if not afr.stop_fut.done(): msg = TileMessages.Set64( tile_index=tile_index, length=1, x=0, y=0, width=8, colors=reorient(tile_index, pixels), res_required=False, ack_required=True, ) await target.script(msg).run_with_all(serial, afr, error_catcher=[], message_timeout=1)
assert part.height == height assert part.left == (2 * 8) assert part.right == (2 * 8) + 5 assert part.top == 3 * 8 assert part.bottom == (3 * 8) - 10 part._set_64.update({"source": 0, "sequence": 1}) real_set_64 = TileMessages.Set64( x=0, y=0, length=1, tile_index=5, colors=[], duration=0, ack_required=False, width=5, res_required=False, target=V.device.serial, source=0, sequence=1, ) assert part._set_64.pack()[36 * 8 :] == real_set_64.payload.pack() it "can be used as a key in dictionary", V: dct = {V.part: 1} assert dct[V.part] == 1 assert dct[(V.device, V.part.part_number)] == 1 assert dct[(V.device.serial, V.part.part_number)] == 1 it "can be compared for equality", V: