Пример #1
0
    async def respond(self, device, pkt, source):
        if pkt | DeviceMessages.GetGroup:
            yield DeviceMessages.StateGroup(
                group=device.attrs.group.uuid,
                label=device.attrs.group.label,
                updated_at=device.attrs.group.updated_at,
            )

        elif pkt | DeviceMessages.GetLocation:
            yield DeviceMessages.StateLocation(
                location=device.attrs.location.uuid,
                label=device.attrs.location.label,
                updated_at=device.attrs.location.updated_at,
            )
Пример #2
0
    def make_response(self, pkt, protocol):
        self.received.append(pkt)

        if pkt | LightMessages.GetInfrared:
            return LightMessages.StateInfrared(brightness=self.infrared)

        if pkt | LightMessages.GetColor:
            return LightMessages.LightState(
                  hue = self.hue
                , saturation = self.saturation
                , brightness = self.brightness
                , kelvin = self.kelvin
                , label = self.label
                , power = self.power
                )

        elif pkt | DeviceMessages.GetVersion:
            return DeviceMessages.StateVersion(
                  vendor = self.vendor_id
                , product = self.product_id
                , version = 0
                )

        elif pkt | DeviceMessages.GetHostFirmware:
            return DeviceMessages.StateHostFirmware(
                  version = self.firmware_version
                , build = self.firmware_build_time
                )

        elif pkt | DeviceMessages.GetGroup:
            return DeviceMessages.StateGroup(
                  group = self.group
                , label = self.group_label
                , updated_at = self.group_updated_at
                )

        elif pkt | DeviceMessages.GetLocation:
            return DeviceMessages.StateLocation(
                  location = self.location
                , label = self.location_label
                , updated_at = self.location_updated_at
                )
Пример #3
0
        replies = [DeviceMessages.StatePower(level=0), DeviceMessages.StatePower(level=65535)]
        e.set_replies(*replies)

        assert e.handled
        assert e.replies == replies

        other = [DeviceMessages.StateLabel()]
        e.set_replies(*other)
        assert e.handled
        assert e.replies == other

    it "can add replies", EKLS, device, io:
        reply1 = DeviceMessages.StatePower()
        reply2 = DeviceMessages.StateLabel()
        reply3 = DeviceMessages.StateGroup()
        reply4 = DeviceMessages.StateLocation()
        reply5 = DeviceMessages.StateInfo()

        e = EKLS(device, io, pkt=DeviceMessages.GetPower())
        assert not e.handled
        assert e.replies is None

        e.add_replies(reply1, reply2)
        assert not e.handled
        assert e.replies == [reply1, reply2]

        e.add_replies([reply3, reply4])
        assert not e.handled
        assert e.replies == [reply1, reply2, reply3, reply4]

        e.add_replies(reply5)
Пример #4
0
            getter = DeviceMessages.GetGroup()
            state = DeviceMessages.StateGroup(group="abcd", label="gl", updated_at=1)
            await device.assertResponse(getter, [state])

            setter = DeviceMessages.SetGroup.empty_normalise(
                group="dcba", label="gl2", updated_at=3
            )
            state = DeviceMessages.StateGroup(group=setter.group, label="gl2", updated_at=3)
            await device.assertResponse(
                setter, [state], group_label="gl2", group_uuid=setter.group, group_updated_at=3
            )
            await device.assertResponse(getter, [state])

        async it "responds to location", device:
            getter = DeviceMessages.GetLocation()
            state = DeviceMessages.StateLocation(location="efef", label="ll", updated_at=2)
            await device.assertResponse(getter, [state])

            setter = DeviceMessages.SetLocation.empty_normalise(
                location="fefe", label="ll2", updated_at=6
            )
            state = DeviceMessages.StateLocation(
                location=setter.location, label="ll2", updated_at=6
            )
            await device.assertResponse(
                setter,
                [state],
                location_label="ll2",
                location_uuid=setter.location,
                location_updated_at=6,
            )