Пример #1
0
        async def gen(serial, sender, **kwargs):
            yield Pipeline([DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")])

        msg = FromGeneratorPerSerial(gen, error_catcher_override=error_catcher_override)

        expected = {
            light1: [DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")],
            light2: [DeviceMessages.GetPower(), DeviceMessages.SetLabel(label="wat")],
            light3: [],
        }

        errors = []

        got = defaultdict(list)
        with light3.offline():
            with light1.no_replies_for(DeviceMessages.SetLabel):
                with light2.no_replies_for(DeviceMessages.GetPower):
                    async for pkt in runner.sender(
                        msg, runner.serials, error_catcher=errors, message_timeout=0.05
                    ):
                        got[pkt.serial].append(pkt)

        assert len(runner.devices) > 0

        for device in runner.devices:
            if device not in expected:
                assert False, f"No expectation for {device.serial}"

            device.compare_received(expected[device])

        assert errors == [
Пример #2
0
            plan = PacketPlan(DeviceMessages.GetPower(), DeviceMessages.StateLabel)
            got = await self.gather(runner, two_lights, {"result": plan})
            assert got == {}

    describe "PresencePlan":

        async it "returns True", runner:
            got = await self.gather(runner, two_lights, "presence")
            assert got == {
                light1.serial: (True, {"presence": True}),
                light2.serial: (True, {"presence": True}),
            }

        async it "allows us to get serials that otherwise wouldn't", runner:
            errors = []
            with light2.no_replies_for(DeviceMessages.GetLabel):
                got = await self.gather(
                    runner,
                    two_lights,
                    "presence",
                    "label",
                    error_catcher=errors,
                    message_timeout=0.1,
                    find_timeout=0.1,
                )

                assert got == {
                    light1.serial: (True, {"presence": True, "label": "bob"}),
                    light2.serial: (False, {"presence": True}),
                }