Exemplo n.º 1
0
def test_invalid_type():
    """Packet where a value type cannot be converted to expected type should not error."""
    packet = "20;2D;RFX10METER;ID=79;TYPE=10;METER=7ef36;"

    assert decode_packet(packet) == {
        "node": "gateway",
        "protocol": "rfx10meter",
        "id": "79",
        "type": "10",
    }
Exemplo n.º 2
0
def test_packet_parsing(packet, expect):
    """Packet should be broken up into their primitives."""
    result = decode_packet(packet)

    for key, value in expect.items():
        assert result[key] == value

    # make sure each packet is serialized without failure
    packet_id = serialize_packet_id(result)

    # and deserialize it again
    packet_identifiers = deserialize_packet_id(packet_id)

    original = set(result.items())
    transserialized = set(packet_identifiers.items())
    assert transserialized.issubset(original)
Exemplo n.º 3
0
    def handle_raw_packet(self, raw_packet):
        """Parse raw packet string into packet dict."""
        log.debug('got packet: %s', raw_packet)
        packet = None
        try:
            packet = decode_packet(raw_packet)
        except:
            log.exception('failed to parse packet: %s', packet)

        log.debug('decoded packet: %s', packet)

        if packet:
            if 'ok' in packet:
                # handle response packets internally
                log.debug('command response: %s', packet)
                self._last_ack = packet
                self._command_ack.set()
            elif self.raw_callback:
                self.raw_callback(raw_packet)
        else:
            log.warning('no valid packet')
Exemplo n.º 4
0
    def handle_raw_packet(self, raw_packet):
        """Parse raw packet string into packet dict."""
        log.debug("got packet: %s", raw_packet)
        packet = None
        try:
            packet = decode_packet(raw_packet)
        except BaseException:
            log.exception("failed to parse packet: %s", packet)

        log.debug("decoded packet: %s", packet)

        if packet:
            if "ok" in packet:
                # handle response packets internally
                log.debug("command response: %s", packet)
                self._last_ack = packet
                self._command_ack.set()
            elif self.raw_callback:
                self.raw_callback(raw_packet)
        else:
            log.warning("no valid packet")