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 )
cap = chp.ProductResponder.capability(device) assert isinstance(cap, Products.LCM3_TILE.cap_kls) assert cap.firmware_major == 3 assert cap.firmware_minor == 50 async it "responds to GetVersion": device, assertProduct = self.make_device( Products.LCMV4_A19_COLOR, chp.Firmware(1, 23, 0) ) async with device: assertProduct() await device.assertResponse( DeviceMessages.GetVersion(), [DeviceMessages.StateVersion(vendor=1, product=22, version=0)], ) device, assertProduct = self.make_device(Products.LCM3_TILE, chp.Firmware(3, 50, 0)) async with device: assertProduct() await device.assertResponse( DeviceMessages.GetVersion(), [DeviceMessages.StateVersion(vendor=1, product=55, version=0)], ) async it "responds to GetHostFirmware": device, assertProduct = self.make_device( Products.LCMV4_A19_COLOR, chp.Firmware(1, 23, 2, 100) ) async with device:
], ) describe "Product": def make_device(self, name, product, firmware): device = devices[name] assert device.cap.product is product assert device.firmware == firmware return device, makeAssertResponse(device) async it "responds to GetVersion": device, assertResponse = self.make_device("a19", Products.LCM2_A19, hp.Firmware(2, 80)) await assertResponse( DeviceMessages.GetVersion(), [DeviceMessages.StateVersion(vendor=1, product=27)], ) device, assertResponse = self.make_device("tile", Products.LCM3_TILE, hp.Firmware(3, 50)) await assertResponse( DeviceMessages.GetVersion(), [DeviceMessages.StateVersion(vendor=1, product=55)], ) async it "responds to GetHostFirmware": device, assertResponse = self.make_device( "color1000", Products.LCMV4_A19_COLOR, hp.Firmware(1, 23) ) device.firmware.build = 2 await assertResponse( DeviceMessages.GetHostFirmware(),