示例#1
0
async def device_annce(app: application.ControllerApplication):
    # payload = {'nwkaddr': 27441, 'extaddr': '0x07a3c302008d1500', 'parentaddr': 0}
    # obj = ZpiObject(2, 5, 'tcDeviceInd', 202, payload, [])

    payload = {'srcaddr': 53322, 'nwkaddr': 53322, 'ieeeaddr': 0x41e54b02008d1500.to_bytes(8, 'little'),
               'capabilities': 132}
    obj = ZpiObject(2, 5, 'endDeviceAnnceInd', 193, payload, [])

    app.handle_znp(obj)
示例#2
0
async def device_annce(app: application.ControllerApplication):
    # payload = {'nwkaddr': 27441, 'extaddr': '0x07a3c302008d1500', 'parentaddr': 0}
    # obj = ZpiObject(2, 5, 'tcDeviceInd', 202, payload, [])

    payload = {
        "srcaddr": 53322,
        "nwkaddr": 53322,
        "ieeeaddr": 0x41E54B02008D1500.to_bytes(8, "little"),
        "capabilities": 132,
    }
    obj = ZpiObject(2, 5, "endDeviceAnnceInd", 193, payload, [])

    app.handle_znp(obj)
示例#3
0
async def test_get_node_descriptor(app: application.ControllerApplication):
    await device_annce(app)
    device = app.get_device(nwk=53322)

    fut = asyncio.Future()
    fut.set_result([0, "message send success"])
    app._api.request_raw = mock.MagicMock(return_value=fut)

    payload = {
        "srcaddr": 53322,
        "status": 0,
        "nwkaddr": 0,
        "logicaltype_cmplxdescavai_userdescavai": 0,
        "apsflags_freqband": 0,
        "maccapflags": 0,
        "manufacturercode": 1234,
        "maxbuffersize": 0,
        "maxintransfersize": 0,
        "servermask": 0,
        "maxouttransfersize": 0,
        "descriptorcap": 0,
    }
    obj = ZpiObject.from_command(5, "nodeDescRsp", payload)
    frame = obj.to_unpi_frame()

    async def nested():
        await asyncio.sleep(0)
        app._api.data_received(frame)

    await asyncio.wait([device.get_node_descriptor(), nested()], timeout=0.2)

    assert isinstance(device.node_desc, zdo_t.NodeDescriptor)
    assert 1234 == device.node_desc.manufacturer_code
示例#4
0
async def test_get_node_descriptor(app: application.ControllerApplication):
    await device_annce(app)
    device = app.get_device(nwk=53322)

    fut = asyncio.Future()
    fut.set_result([0, 'message send success'])
    app._api.request_raw = mock.MagicMock(return_value=fut)

    payload = {'srcaddr': 53322, 'status': 0, 'nwkaddr': 0, 'logicaltype_cmplxdescavai_userdescavai': 0,
               'apsflags_freqband': 0, 'maccapflags': 0, 'manufacturercode': 1234, 'maxbuffersize': 0,
               'maxintransfersize': 0, 'servermask': 0, 'maxouttransfersize': 0, 'descriptorcap': 0}
    obj = ZpiObject.from_command(2, 5, 'nodeDescRsp', payload)
    frame = obj.to_unpi_frame()

    async def nested():
        await asyncio.sleep(0)
        app._api.data_received(frame)

    await asyncio.wait([
        device.get_node_descriptor(),
        nested(),
    ], timeout=0.2)

    assert isinstance(device.node_desc, zdo_t.NodeDescriptor)
    assert device.node_desc.manufacturer_code == 1234
示例#5
0
async def test_request(app: application.ControllerApplication):
    await device_annce(app)
    device = app.get_device(nwk=53322)

    fut = asyncio.Future()
    fut.set_result(None)
    app._api.request_raw = mock.MagicMock(return_value=fut)

    res = await app.request(device, 0, zdo_t.ZDOCmd.Node_Desc_req, 0, 0, 1,
                            b"\x01\xa2\x2e")

    assert len(app._api._waiters) == 1
    assert res == (0, "message send success")
示例#6
0
async def test_request(app: application.ControllerApplication):
    await device_annce(app)
    device = app.get_device(nwk=53322)

    fut = asyncio.Future()
    fut.set_result(None)
    app._api.request_raw = mock.MagicMock(return_value=fut)

    res = await app.request(device, 0, zdo_t.ZDOCmd.Node_Desc_req, 0, 0, 1,
                            b"\x01\xa2\x2e")

    assert len(app._api._waiters) == 1
    assert (
        "SREQ ZDO nodeDescReq tsn: 1 {'dstaddr': 0xd04a, 'nwkaddrofinterest': 0x2ea2}"
        == str(app._api.request_raw.call_args[0][0]))
    assert res == (0, "message send success")
示例#7
0
async def test_read_attributes(app: application.ControllerApplication):
    await device_annce(app)
    device = app.get_device(nwk=53322)