예제 #1
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
                )
예제 #2
0
    describe "InfraredResponder":

        @pytest.fixture()
        async def device(self):
            device = Device(
                chp.ProductResponder.from_product(Products.LCM2_A19_PLUS), chp.InfraredResponder()
            )

            async with device:
                device.assertAttrs(infrared=0)
                yield device

        async it "responds to infrared messages", device:
            await device.assertResponse(
                LightMessages.GetInfrared(), [LightMessages.StateInfrared(brightness=0)]
            )
            await device.assertResponse(
                LightMessages.SetInfrared(brightness=100),
                [LightMessages.StateInfrared(brightness=0)],
                infrared=100,
            )
            await device.assertResponse(
                LightMessages.GetInfrared(),
                [LightMessages.StateInfrared(brightness=100)],
                infrared=100,
            )

        async it "doesn't respond to infrared if the product doesn't have infrared":
            device = Device(
                chp.ProductResponder.from_product(Products.LCM2_A19), chp.InfraredResponder()