async def test_internal_version(command, message_schema, transport):
    """Test internal version command."""
    gateway = Gateway(transport)

    async for msg in gateway.listen():
        assert message_schema.dump(msg) == command
        break

    assert gateway.protocol_version == "2.0"
Пример #2
0
async def test_unset_protocol_version(message, message_schema, node, child,
                                      transport):
    """Test gateway listen."""
    gateway = Gateway(transport)
    gateway.nodes[0] = node
    cmd = message_schema.dump(message)

    async with gateway:
        async for msg in gateway.listen():
            assert message_schema.dump(msg) == cmd
            break

    assert gateway.transport.writes == [
        message_schema.dump(Message(0, 255, 3, 0, 2, ""))
    ]
async def test_presentation_gateway_protocol_version(protocol_version,
                                                     message_schema,
                                                     transport):
    """Test that gateway presentation sets protocol version."""
    gateway = Gateway(transport)
    message = Message(0, 255, 0, 0, 17, protocol_version)
    command = message_schema.dump(message)
    transport.messages.append(command)
    assert gateway.protocol_version is None

    async for msg in gateway.listen():
        assert message_schema.dump(msg) == command
        break

    assert gateway.protocol_version == protocol_version
    assert gateway.protocol is get_protocol(protocol_version)
Пример #4
0
 async def gateway_factory() -> Gateway:
     """Return a gateway."""
     transport = MQTTClient(host, port, in_prefix, out_prefix)
     gateway = Gateway(transport)
     return gateway
Пример #5
0
 async def gateway_factory() -> Gateway:
     """Return a gateway."""
     transport = TCPTransport(host, port)
     gateway = Gateway(transport)
     return gateway
Пример #6
0
 async def gateway_factory() -> Gateway:
     """Return a gateway."""
     transport = SerialTransport(port, baud)
     gateway = Gateway(transport)
     return gateway
Пример #7
0
async def handle_gateway(gateway: Gateway) -> None:
    """Handle the gateway calls."""
    async for msg in gateway.listen():  # pragma: no cover
        level = logging.DEBUG if msg.message_type == 9 else logging.INFO
        LOGGER.log(level, "Received: %s", msg)
Пример #8
0
def gateway_fixture(message_schema, transport):
    """Mock a gateway."""
    gateway = Gateway(transport)
    gateway.protocol_version = message_schema.context.get(
        "protocol_version", "1.4")
    return gateway