Ejemplo n.º 1
0
    def get_zones(self, start_index=0, end_index=255):
        buf = []
        bufs = []

        for i, zone in enumerate(self.device.attrs.zones):
            if i < start_index or i > end_index:
                continue

            if len(buf) == 8:
                bufs.append(buf)
                buf = []

            buf.append((i, zone))

        if buf:
            bufs.append(buf)

        for buf in bufs:
            if len(buf) == 1:
                yield MultiZoneMessages.StateZone(
                    zones_count=len(self.device.attrs.zones),
                    zone_index=buf[0][0],
                    **buf[0][1].as_dict(),
                )
                continue

            yield MultiZoneMessages.StateMultiZone(
                zones_count=len(self.device.attrs.zones),
                zone_index=buf[0][0],
                colors=[b.as_dict() for _, b in buf],
            )
Ejemplo n.º 2
0
                MultiZoneMessages.StateMultiZone(zones_count=11, zone_index=0, colors=zones[0:8]),
                MultiZoneMessages.StateMultiZone(zones_count=11, zone_index=8, colors=zones[8:]),
            ],
        )

        await assertResponse(
            MultiZoneMessages.GetColorZones(start_index=0, end_index=9),
            [
                MultiZoneMessages.StateMultiZone(zones_count=11, zone_index=0, colors=zones[0:8]),
                MultiZoneMessages.StateMultiZone(zones_count=11, zone_index=8, colors=zones[8:10]),
            ],
        )

        await assertResponse(
            MultiZoneMessages.GetColorZones(start_index=0, end_index=0),
            [MultiZoneMessages.StateZone(zones_count=11, zone_index=0, **zones[0].as_dict())],
        )

        await assertResponse(
            MultiZoneMessages.SetColorZones(
                start_index=7,
                end_index=8,
                hue=100,
                saturation=0,
                brightness=0.1,
                kelvin=6500,
            ),
            [
                MultiZoneMessages.StateMultiZone(zones_count=11, zone_index=7, colors=zones[7:9]),
            ],
        )