コード例 #1
0
ファイル: test_appdb.py プロジェクト: vzenrhen/zigpy
 def _initialize(self):
     self.status = status
     self.initializing = False
     self.node_desc = zdo_t.NodeDescriptor(0, 1, 2, 3, 4, 5, 6, 7, 8)
コード例 #2
0
ファイル: test_appdb.py プロジェクト: vzenrhen/zigpy
async def test_neighbors(tmpdir):
    """Test neighbor loading."""

    ext_pid = t.EUI64.convert("aa:bb:cc:dd:ee:ff:01:02")
    ieee_1 = make_ieee(1)
    nwk_1 = 0x1111
    nei_1 = zdo_t.Neighbor(ext_pid, ieee_1, nwk_1, 0x16, 0, 15, 250)

    ieee_2 = make_ieee(2)
    nwk_2 = 0x2222
    nei_2 = zdo_t.Neighbor(ext_pid, ieee_2, nwk_2, 0x25, 0, 15, 250)

    ieee_3 = make_ieee(3)
    nwk_3 = 0x3333
    nei_3 = zdo_t.Neighbor(ext_pid, ieee_3, nwk_3, 0x25, 0, 15, 250)

    db = os.path.join(str(tmpdir), "test.db")
    app = await make_app(db)
    app.handle_join(nwk_1, ieee_1, 0)

    dev_1 = app.get_device(ieee_1)
    dev_1.node_desc = zdo_t.NodeDescriptor(2, 64, 128, 4174, 82, 82, 0, 82, 0)
    app.device_initialized(dev_1)

    # 2nd device
    app.handle_join(nwk_2, ieee_2, 0)
    dev_2 = app.get_device(ieee_2)
    dev_2.node_desc = zdo_t.NodeDescriptor(1, 64, 142, 4476, 82, 82, 0, 82, 0)
    app.device_initialized(dev_2)

    neighbors = zdo_t.Neighbors(2, 0, [nei_2, nei_3])
    p1 = patch.object(
        dev_1.zdo,
        "request",
        new=AsyncMock(return_value=(zdo_t.Status.SUCCESS, neighbors)),
    )
    with p1:
        res = await dev_1.neighbors.scan()
        assert res

    neighbors = zdo_t.Neighbors(2, 0, [nei_1, nei_3])
    p1 = patch.object(
        dev_2.zdo,
        "request",
        new=AsyncMock(return_value=(zdo_t.Status.SUCCESS, neighbors)),
    )
    with p1:
        res = await dev_2.neighbors.scan()
        assert res

    del dev_1, dev_2
    # Everything should've been saved - check that it re-loads
    app2 = await make_app(db)
    dev_1 = app2.get_device(ieee_1)
    dev_2 = app2.get_device(ieee_2)

    assert len(dev_1.neighbors) == 2
    assert dev_1.neighbors[0].device is dev_2
    assert dev_1.neighbors[1].device is None
    assert dev_1.neighbors[1].neighbor.ieee == ieee_3

    assert len(dev_2.neighbors.neighbors) == 2
    assert dev_2.neighbors[0].device is dev_1
    assert dev_2.neighbors[1].device is None
    assert dev_2.neighbors[1].neighbor.ieee == ieee_3
コード例 #3
0
 def _initialize(self):
     if initialize:
         self.node_desc = zdo_t.NodeDescriptor(0, 1, 2, 3, 4, 5, 6, 7, 8)
コード例 #4
0
async def test_migration_from_3_to_4(open_twice, test_db):
    test_db_v3 = test_db("simple_v3.sql")

    with sqlite3.connect(test_db_v3) as conn:
        cur = conn.cursor()

        neighbors_before = list(cur.execute("SELECT * FROM neighbors"))
        assert len(neighbors_before) == 2
        assert all([len(row) == 8 for row in neighbors_before])

        node_descs_before = list(cur.execute("SELECT * FROM node_descriptors"))
        assert len(node_descs_before) == 2
        assert all([len(row) == 2 for row in node_descs_before])

    # Ensure migration works on first run, and after shutdown
    if open_twice:
        app = await make_app(test_db_v3)
        await app.pre_shutdown()

    app = await make_app(test_db_v3)

    dev1 = app.get_device(nwk=0xBD4D)
    assert dev1.node_desc == zdo_t.NodeDescriptor(
        logical_type=zdo_t.LogicalType.Router,
        complex_descriptor_available=0,
        user_descriptor_available=0,
        reserved=0,
        aps_flags=0,
        frequency_band=zdo_t.NodeDescriptor.FrequencyBand.Freq2400MHz,
        mac_capability_flags=142,
        manufacturer_code=4476,
        maximum_buffer_size=82,
        maximum_incoming_transfer_size=82,
        server_mask=11264,
        maximum_outgoing_transfer_size=82,
        descriptor_capability_field=0,
    )
    assert len(dev1.neighbors) == 1
    assert dev1.neighbors[0].neighbor == zdo_t.Neighbor(
        extended_pan_id=t.ExtendedPanId.convert("81:b1:12:dc:9f:bd:f4:b6"),
        ieee=t.EUI64.convert("ec:1b:bd:ff:fe:54:4f:40"),
        nwk=0x6D1C,
        reserved1=0,
        device_type=zdo_t.Neighbor.DeviceType.Router,
        rx_on_when_idle=1,
        relationship=zdo_t.Neighbor.RelationShip.Sibling,
        reserved2=0,
        permit_joining=2,
        depth=15,
        lqi=130,
    )

    dev2 = app.get_device(nwk=0x6D1C)
    assert dev2.node_desc == dev1.node_desc.replace(manufacturer_code=4456)
    assert len(dev2.neighbors) == 1
    assert dev2.neighbors[0].neighbor == zdo_t.Neighbor(
        extended_pan_id=t.ExtendedPanId.convert("81:b1:12:dc:9f:bd:f4:b6"),
        ieee=t.EUI64.convert("00:0d:6f:ff:fe:a6:11:7a"),
        nwk=0xBD4D,
        reserved1=0,
        device_type=zdo_t.Neighbor.DeviceType.Router,
        rx_on_when_idle=1,
        relationship=zdo_t.Neighbor.RelationShip.Sibling,
        reserved2=0,
        permit_joining=2,
        depth=15,
        lqi=132,
    )

    await app.pre_shutdown()

    with sqlite3.connect(test_db_v3) as conn:
        cur = conn.cursor()

        # Old tables are untouched
        assert neighbors_before == list(cur.execute("SELECT * FROM neighbors"))
        assert node_descs_before == list(
            cur.execute("SELECT * FROM node_descriptors"))

        # New tables exist
        neighbors_after = list(cur.execute("SELECT * FROM neighbors_v4"))
        assert len(neighbors_after) == 2
        assert all([len(row) == 12 for row in neighbors_after])

        node_descs_after = list(
            cur.execute("SELECT * FROM node_descriptors_v4"))
        assert len(node_descs_after) == 2
        assert all([len(row) == 14 for row in node_descs_after])
コード例 #5
0
ファイル: appdb.py プロジェクト: Adminiuga/zigpy
 async def _load_node_descriptors(self) -> None:
     async with self.execute(f"SELECT * FROM node_descriptors{DB_V}") as cursor:
         async for (ieee, *fields) in cursor:
             dev = self._application.get_device(ieee)
             dev.node_desc = zdo_t.NodeDescriptor(*fields)
             assert dev.node_desc.is_valid
コード例 #6
0
ファイル: test_appdb.py プロジェクト: zsyg/zigpy
 def _initialize(self):
     self.status = status
     self.initializing = False
     self._application.device_initialized(self)
     self.node_desc = zdo_t.NodeDescriptor(0, 1, 2, 3, 4, 5, 6, 7, 8)