Esempio n. 1
0
    async def execute_task(self, **kwargs):
        extra = self.photons_app.extra_as_json
        message_register = protocol_register.message_register(1024)

        if "extra_payload_kwargs" in kwargs:
            extra.update(kwargs["extra_payload_kwargs"])

        packd = Messages.pack_payload(self.reference, extra, message_register)
        print(binascii.hexlify(packd.tobytes()).decode())
Esempio n. 2
0
async def pack_payload(collector, reference, **kwargs):
    """
    Pack json found after the ``--`` into hexlified string

    ``pack_payload 117 -- '{"level": 65535, "duration": 10}'``
    """
    extra = collector.configuration["photons_app"].extra_as_json
    protocol_register = collector.configuration["protocol_register"]
    message_register = protocol_register.message_register(1024)

    if "extra_payload_kwargs" in kwargs:
        extra.update(kwargs["extra_payload_kwargs"])

    packd = Messages.pack_payload(reference, extra, message_register)
    print(binascii.hexlify(packd.tobytes()).decode())
Esempio n. 3
0
            get_packet_type.return_value = (1024, 78, LIFXPacket, None, data)

            msg = "Unknown message type!"
            with assertRaises(BadConversion, msg, protocol=1024, pkt_type=78):
                with mock.patch.object(Messages, "get_packet_type", get_packet_type):
                    Messages.create(data, protocol_register, unknown_ok=False)

            get_packet_type.assert_called_once_with(data, protocol_register)

    describe "pack_payload":
        it "works", protocol_register, TestMessages:
            bts = TestMessages.One(one="sh").payload.pack()

            data = {"one": "sh"}
            mr = protocol_register.message_register(1024)
            assert Messages.pack_payload(78, data, mr) == bts

            assert TestMessages.pack_payload(78, data) == bts

        it "complains if the message_type is unknown", protocol_register:
            data = mock.Mock(name="data")
            with assertRaises(BadConversion, "Unknown message type!", pkt_type=87):
                Messages.pack_payload(87, data, protocol_register.message_register(1024))

    describe "pack":
        it "works", protocol_register, TestMessages:
            data = {
                "protocol": 1024,
                "pkt_type": 78,
                "one": "ii",
                "source": 4,