async def process_incoming(self, bts, give_reply, addr): if not self.device.has_power: return pkt = Messages.create(bts, protocol_register=self.device.protocol_register) event = await self.device.event_with_options( Events.INCOMING, execute=False, args=(self, ), kwargs=dict(pkt=pkt, addr=addr), ) processed = await self.packet_filter.process_request(event) if processed is None: event = await self.device.event(Events.LOST, self, pkt=pkt, addr=addr) return await self.device.execute_event(event, lambda e: e.handled) await self.process_instruction(SendAck(event), give_reply) if processed is False: await self.device.event(Events.IGNORED, self, pkt=event.pkt, bts=event.bts, addr=event.addr) return if event.ignored: await self.device.event(Events.IGNORED, self, pkt=event.pkt, bts=event.bts, addr=event.addr) elif not event.handled and not event.replies: await self.device.event(Events.UNHANDLED, self, pkt=event.pkt, bts=event.bts, addr=event.addr) await self.process_instruction(SendUnhandled(event), give_reply) else: await self.process_instruction(SendReplies(event), give_reply)
async def execute_task(self, **kwargs): bts = base64.b64decode(self.photons_app.extra) pkt = Messages.create(bts, protocol_register, unknown_ok=True) print(repr(pkt))
async def execute_task(self, **kwargs): bts = binascii.unhexlify(self.photons_app.extra) pkt = Messages.create(bts, protocol_register, unknown_ok=True) print(repr(pkt))
assert msg.payload.actual("skew_ratio") == 32767 assert msg.payload.actual("waveform") == 1 assert msg.payload.actual("set_hue") == 1 assert msg.payload.actual("set_saturation") == 0 assert msg.payload.actual("set_brightness") == 1 assert msg.payload.actual("set_kelvin") == 1 it "SetWaveformOptional does not require all hsbk values": msg = LightMessages.SetWaveformOptional(hue=100, source=1, sequence=0, target=None) assert msg.actual("brightness") is sb.NotSpecified assert msg.set_hue == 1 assert msg.set_saturation == 0 assert msg.set_brightness == 0 assert msg.set_kelvin == 0 unpackd = Messages.create(msg.pack(), protocol_register=protocol_register) assert unpackd.hue == pytest.approx(100, rel=1e-2) assert unpackd.set_hue == 1 assert unpackd.set_saturation == 0 assert unpackd.saturation == 0 assert unpackd.set_brightness == 0 assert unpackd.brightness == 0 assert unpackd.set_kelvin == 0 assert unpackd.kelvin == 0 msg = LightMessages.SetWaveformOptional.create(hue=100, source=1, sequence=0, target=None) assert msg.actual("brightness") is Optional assert msg.set_hue == 1 assert msg.set_saturation == 0
def make_message(bts): return Messages.create(bts, protocol_register=protocol_register)
it "converts str to bytes", protocol_register, TestMessages: data = "AA" asbytes = binascii.unhexlify(data) packet_type = mock.Mock(name="packet_type", return_value=(1024, 78)) with mock.patch.object(PacketTypeExtractor, "packet_type", packet_type): info = Messages.get_packet_type(data, protocol_register) assert info == (1024, 78, LIFXPacket, TestMessages.One, asbytes) packet_type.assert_called_once_with(asbytes) describe "create": it "works", protocol_register, TestMessages: bts = TestMessages.One(source=1, sequence=2, target="d073d5000001", one="bl").pack() pkt = Messages.create(bts, protocol_register) assert pkt | TestMessages.One, pkt.__class__ assert pkt.one == "bl" assert pkt.pack() == bts it "works with unknown packet", protocol_register: bts = LIFXPacket( pkt_type=100, source=1, sequence=2, target="d073d5000001", payload="AA" ).pack() pkt = Messages.create(bts, protocol_register, unknown_ok=True) assert isinstance(pkt, LIFXPacket) assert pkt.payload == binascii.unhexlify("AA") assert pkt.pack() == bts