예제 #1
0
async def test_manual_bus(mock_clock):
    class Checkpoint:
        pass

    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker(  # pylint: disable=unused-variable
        [
            ServerRegistered,
            ServerConnected,
            BusAdded_Path("bus.0"),
            DeviceAdded("10.345678.90"),
            DeviceLocated("10.345678.90"),
            Checkpoint,
            Checkpoint,
            ServerDisconnected,
            DeviceNotFound("10.345678.90"),
            BusDeleted,
            ServerDeregistered,
        ])
    async with server(tree=basic_tree, scan=None,
                      initial_scan=False) as ow:  # events=e1,
        bus = await ow.test_server.get_bus("bus.0")
        assert bus.server == ow.test_server

        dev = await ow.get_device("10.345678.90")
        assert dev.bus is None
        await dev.locate(bus)
        assert dev.bus is not None
        assert float(await dev.attr_get("temperature")) == 12.5
예제 #2
0
async def test_empty_server():
    e1 = EventChecker([
        ServerRegistered, ServerConnected, ServerDisconnected,
        ServerDeregistered
    ])
    async with server(events=e1):  # as ow:
        await trio.sleep(0)
예제 #3
0
async def test_dropped_device(mock_clock):
    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        BusAdded,
        DeviceAdded("10.345678.90"),
        DeviceLocated("10.345678.90"),
        DeviceNotFound("10.345678.90"),
        ServerDisconnected,
        BusDeleted,
        ServerDeregistered,
    ])
    my_tree = deepcopy(basic_tree)
    async with server(tree=my_tree, events=e1) as ow:
        dev = await ow.get_device("10.345678.90")
        assert dev.bus is not None
        del my_tree["bus.0"]["10.345678.90"]
        assert dev._unseen == 0

        await ow.scan_now(polling=False)
        assert dev._unseen == 1
        await ow.scan_now(polling=False)
        assert dev._unseen == 2
        await ow.scan_now(polling=False)
        assert dev._unseen == 3
        assert dev.bus is not None
        await ow.scan_now(polling=False)
        assert dev._unseen == 3
        assert dev.bus is None
예제 #4
0
async def test_manual_device(mock_clock):
    class Checkpoint:
        pass

    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        BusAdded,
        Checkpoint,
        DeviceAdded("10.345678.90"),
        Checkpoint,
        DeviceLocated("10.345678.90"),
        ServerDisconnected,
        DeviceNotFound("10.345678.90"),
        BusDeleted,
        ServerDeregistered,
    ])
    my_tree = deepcopy(basic_tree)
    entry = my_tree["bus.0"].pop("10.345678.90")
    async with server(events=e1, tree=my_tree) as ow:
        await ow.push_event(Checkpoint())
        dev = await ow.get_device("10.345678.90")
        assert dev.bus is None
        await trio.sleep(15)
        await ow.push_event(Checkpoint())
        my_tree["bus.0"]["10.345678.90"] = entry
        await ow.scan_now(polling=False)
        assert dev.bus is not None
예제 #5
0
async def test_coupler_server(mock_clock):
    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker(  # pylint: disable=unused-variable
        [
            ServerRegistered,
            ServerConnected,
            BusAdded_Path("bus.0"),
            DeviceAdded("10.345678.90"),
            DeviceLocated("10.345678.90"),
            DeviceAdded("1F.ABCDEF.F1"),
            DeviceLocated("1F.ABCDEF.F1"),
            BusAdded_Path("bus.0", "1F.ABCDEF.F1", "main"),
            DeviceAdded("20.222222.22"),
            DeviceLocated("20.222222.22"),
            BusAdded_Path("bus.0", "1F.ABCDEF.F1", "aux"),
            DeviceAdded("28.282828.28"),
            DeviceLocated("28.282828.28"),
            ServerDisconnected,
            DeviceNotFound,
            BusDeleted,
            DeviceNotFound,
            BusDeleted,
            DeviceNotFound,
            DeviceNotFound,
            BusDeleted,
            ServerDeregistered,
        ])
    async with server(
            tree=coupler_tree):  # events=e1, tree=coupler_tree):  # as ow:
        await trio.sleep(0)
예제 #6
0
async def test_disconnecting_server_2(mock_clock):
    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker(  # pylint: disable=unused-variable
        [
            ServerRegistered,
            ServerConnected,
            ServerDisconnected,
            ServerConnected,
            ServerDisconnected,
            ServerConnected,
            BusAdded,
            ServerDisconnected,
            ServerConnected,
            DeviceAdded("10.345678.90"),
            DeviceLocated("10.345678.90"),
            ServerDisconnected,
            DeviceNotFound("10.345678.90"),
            BusDeleted,
            ServerDeregistered,
        ])
    async with server(
            tree=basic_tree,
            options={"close_every": [0, 0, 1, 0,
                                     0]}  # events=e1, tree=basic_tree,
    ):  # as ow:
        await trio.sleep(0)
예제 #7
0
async def test_alarm(mock_clock):
    e1 = EventChecker(  # pylint: disable=unused-variable
        [
            ServerRegistered,
            ServerConnected,
            BusAdded,
            DeviceAdded("10.345678.90"),
            DeviceLocated("10.345678.90"),
            DeviceAlarm("10.345678.90"),
            DeviceValue("10.345678.90", "temperature", 12.5),
            # DeviceValue("10.345678.90", "temperature",12.5),
            # DeviceNotFound("10.345678.90"),
            ServerDisconnected,
            DeviceNotFound("10.345678.90"),
            BusDeleted,
            ServerDeregistered,
        ])
    mock_clock.autojump_threshold = 0.1
    my_tree = deepcopy(basic_tree)
    dt = my_tree["bus.0"].pop("10.345678.90")
    async with server(tree=my_tree) as ow:  # , polling=True, events=e1) as ow:
        dev = await ow.get_device("10.345678.90")
        dev.interval_alarm = 10
        dev.interval_temperature = 15

        my_tree["bus.0"]["10.345678.90"] = dt
        await ow.scan_now()
        my_tree["bus.0"]["alarm"]["10.345678.90"] = dt
        await trio.sleep(12)  # allow alarm poll to trigger
        assert int(dt["temphigh"]) == 20
        assert int(dt["templow"]) == 11
        assert dev.alarm_temperature == 12.5
        await trio.sleep(5)  # allow temperature poll to trigger
예제 #8
0
async def test_send_idle(mock_clock):
    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker([
        ServerRegistered, ServerConnected, ServerDisconnected,
        ServerDeregistered
    ])
    async with server(events=e1):  # as ow:
        await trio.sleep(15)
예제 #9
0
async def test_bad_event():
    e1 = EventChecker([
        ServerRegistered, ServerConnected, ServerConnected, ServerDeregistered
    ])
    with pytest.raises(RuntimeError) as r:
        async with server(events=e1):  # as ow:
            await trio.sleep(0)
    assert "Wrong event: want " in r.value.args[0]
예제 #10
0
async def test_more_event():
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        ServerDisconnected,
        ServerDeregistered,
        ServerDeregistered,
    ])
    with pytest.raises(RuntimeError) as r:
        async with server(events=e1):  # as ow:
            await trio.sleep(0)
    assert "Superfluous event " in r.value.args[0]
예제 #11
0
async def test_wrong_bus():
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        BusAdded_Path("bus.0"),
        DeviceAdded("10.345678.90"),
        DeviceLocated("10.345678.90"),
        ServerDisconnected,
        ServerDeregistered,
    ])
    with pytest.raises(RuntimeError) as r:
        async with server(events=e1, tree=basic_tree):  # as ow:
            await trio.sleep(0)
    assert "Wrong event: want " in r.value.args[0]
예제 #12
0
async def test_slow_server(mock_clock):
    mock_clock.autojump_threshold = 0.1
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        BusAdded,
        DeviceAdded("10.345678.90"),
        DeviceLocated("10.345678.90"),
        ServerDisconnected,
        DeviceNotFound("10.345678.90"),
        BusDeleted,
        ServerDeregistered,
    ])
    async with server(events=e1,
                      tree=basic_tree,
                      options={"slow_every": [0, 0, 5, 0, 0]}):  # as ow:
        await trio.sleep(0)
예제 #13
0
async def test_busy_server():
    e1 = EventChecker([
        ServerRegistered,
        ServerConnected,
        BusAdded,
        DeviceAdded("10.345678.90"),
        DeviceLocated("10.345678.90"),
        ServerDisconnected,
        DeviceNotFound("10.345678.90"),
        BusDeleted,
        ServerDeregistered,
    ])
    async with server(events=e1,
                      tree=basic_tree,
                      options={"busy_every": [0, 0, 1]}):
        await trio.sleep(0)
    async with server(events=e1,
                      tree=basic_tree,
                      options={"busy_every": [1, 0, 1]}):
        await trio.sleep(0)
예제 #14
0
async def test_basic_server():
    e1 = EventChecker(  # pylint: disable=unused-variable
        [
            ServerRegistered,
            ServerConnected,
            BusAdded_Path("bus.0"),
            DeviceAdded("10.345678.90"),
            DeviceLocated("10.345678.90"),
            ServerDisconnected,
            DeviceNotFound,
            BusDeleted,
            ServerDeregistered,
        ])
    async with server(tree=basic_tree) as ow:  # events=e1) as ow:
        await trio.sleep(0)
        dev = await ow.get_device("10.345678.90")
        assert dev.bus == ("bus.0", )
        assert isinstance(dev.bus, Bus)
        assert float(await dev.attr_get("temperature")) == 12.5
        await dev.attr_set("temperature", value=98.25)
        assert float(await dev.attr_get("temperature")) == 98.25
        await dev.attr_set("temperature", value=12.5)
예제 #15
0
async def test_missing_event():
    e1 = EventChecker([ServerRegistered, ServerConnected, ServerDisconnected])
    with pytest.raises(RuntimeError) as r:
        async with server(events=e1):  # as ow:
            await trio.sleep(0)
    assert "Unexpected event " in r.value.args[0]