Beispiel #1
0
    def _msgs(self, colors, acks=False, duration=1, randomize=False):
        if self.device.cap.has_matrix:
            colors = [
                c if c is not None else None
                for c in self.reorient(colors, randomize=randomize)
            ]

            kwargs = {"colors": colors}
            if duration != 0:
                kwargs["duration"] = duration
            if acks:
                kwargs["acks"] = acks

            msg = self._set_64.clone()
            msg.update(kwargs)
            return (msg, )

        elif self.device.cap.has_multizone:
            return MultizoneMessagesMaker(self.device.serial,
                                          self.device.cap,
                                          colors,
                                          duration=duration).msgs

        elif colors:
            if isinstance(colors[0], tuple):
                h, s, b, k = colors[0]
                info = {
                    "hue": h,
                    "saturation": s,
                    "brightness": b,
                    "kelvin": k,
                }
            else:
                info = colors[0].as_dict()

            info["duration"] = duration
            return (LightMessages.SetColor(target=self.device.serial,
                                           res_required=False,
                                           **info), )
Beispiel #2
0
            ack = CoreMessages.Acknowledgement(source=20, sequence=2, target="d073d5001111")
            self.assertLines(ack, f"Ack(source={ack.source},sequence=2,target=d073d5001111)(empty)")

        it "can format simple messages":
            pkt = DeviceMessages.GetPower(source=21, sequence=3, target="d073d5002222")
            self.assertLines(
                pkt,
                f"GetPower(ack=True,res=True,source={pkt.source},sequence=3,target=d073d5002222)(empty)",
            )

        it "can format messages with fields":
            pkt = LightMessages.SetColor(
                res_required=False,
                source=22,
                sequence=4,
                target="d073d5003333",
                hue=200,
                saturation=1,
                brightness=0.5,
                kelvin=9000,
            )
            self.assertLines(
                pkt,
                f"SetColor(ack=True,res=False,source={pkt.source},sequence=4,target=d073d5003333)",
                mock.ANY,
                "  hue: 200.0",
                "  saturation: 1.0",
                "  brightness: 0.5",
                "  kelvin: 9000",
                "  duration: 0.0",
            )
Beispiel #3
0
        reorient.assert_called_once_with(colors, part.random_orientation)

    describe "msgs":
        it "returns a SetColor for bulbs", V:
            device = cont.Device("d073d5001337", Products.LCM2_A19.cap)
            part = V.make_part(device, 0, user_x=2, user_y=2, width=1, height=1)

            colors = [(100, 1, 0.4, 2400)]
            msgs = list(part.msgs(colors, duration=100))
            assert len(msgs) == 1
            assert msgs[0] | LightMessages.SetColor
            assert (
                msgs[0].payload
                == LightMessages.SetColor(
                    hue=100, saturation=1, brightness=0.4, kelvin=2400, duration=100
                ).payload
            )

        it "returns multizone messages for strips", V:
            colors = mock.Mock(name="colors", spec=[])
            duration = mock.Mock(name="duration", spec=[])

            lcm2_cap = Products.LCM2_Z.cap(2, 80)
            assert lcm2_cap.has_extended_multizone

            m1 = mock.Mock(name="m1")
            m2 = mock.Mock(name="m2")

            maker = mock.Mock(name="maker", spec=["msgs"], msgs=[m1, m2])
            FakeMultizoneMessagesMaker = mock.Mock(name="message maker", return_value=maker)
Beispiel #4
0
        async def see_request(event):
            if event | DeviceMessages.SetPower:
                called.append(event.pkt.serial)
                if len(called) == 3 and not wait.done():
                    wait.set_result(True)
                    await asyncio.sleep(0)
                await wait

        isr1 = light1.io["MEMORY"].packet_filter.intercept_see_request(see_request)
        isr2 = light2.io["MEMORY"].packet_filter.intercept_see_request(see_request)
        isr3 = light3.io["MEMORY"].packet_filter.intercept_see_request(see_request)

        msgs = [
            DeviceMessages.SetPower(level=0),
            LightMessages.SetColor(hue=0, saturation=0, brightness=1, kelvin=4500),
        ]

        got = defaultdict(list)

        with isr1, isr2, isr3:
            async for pkt in sender(msgs, reference):
                print(pkt.serial, type(pkt.payload))
                got[pkt.serial].append(pkt)

        assert all(serial in got for serial in devices.serials), got

        for serial, pkts in got.items():
            print(f"GOT: {serial}")
            for p in pkts:
                print("\t", type(p.payload), repr(p.payload))
Beispiel #5
0
                [DeviceMessages.StateLabel(label="bob")],
                label="bob",
            )
            await device.assertResponse(
                LightMessages.GetColor(), [light_state("bob", 0, 0, 0, 1, 3500)]
            )

            await device.assertResponse(
                DeviceMessages.SetPower(level=300), [DeviceMessages.StatePower(level=0)], power=300
            )
            await device.assertResponse(
                LightMessages.GetColor(), [light_state("bob", 300, 0, 0, 1, 3500)]
            )

            await device.assertResponse(
                LightMessages.SetColor(hue=100, saturation=0.5, brightness=0.5, kelvin=4500),
                [light_state("bob", 300, 0, 0, 1, 3500)],
            )
            await device.assertResponse(
                LightMessages.GetColor(), [light_state("bob", 300, 100, 0.5, 0.5, 4500)]
            )

            await device.assertResponse(
                LightMessages.SetWaveform(
                    hue=200, saturation=0.6, brightness=0.4, kelvin=9000, waveform=Waveform.SAW
                ),
                [light_state("bob", 300, 100, 0.5, 0.5, 4500)],
            )
            await device.assertResponse(
                LightMessages.GetColor(), [light_state("bob", 300, 200, 0.6, 0.4, 9000)]
            )