def test_bind_req_serialize(): payload = {"dstaddr": NWK(25234), "srcaddr": EUI64(reversed(b'\x00\x0b\x57\xff\xfe\x27\x78\x3c')), "srcendpoint": 1, "clusterid": 8, "dstaddrmode": 3, "dstaddress": EUI64(reversed(b'\x00\x12\x4b\x00\x18\xed\x25\x0c')), "dstendpoint": 1} obj = ZpiObject.from_command(t.Subsystem.ZDO, 'bindReq', payload) assert ( "SREQ ZDO bindReq tsn: None {" "'dstaddr': 0x6292, " "'srcaddr': 00:0b:57:ff:fe:27:78:3c, " "'srcendpoint': 1, " "'clusterid': 8, " "'dstaddrmode': 3, " "'dstaddress': 00:12:4b:00:18:ed:25:0c, " "'dstendpoint': 1}" == str(obj) ) assert ( bytes( [254, 23, 37, 33, 146, 98, 60, 120, 39, 254, 255, 87, 11, 0, 1, 8, 0, 3, 12, 37, 237, 24, 0, 75, 18, 0, 1, 83]) == obj.to_unpi_frame().to_buffer() )
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
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
def test_from_unpi_frame3(): payload = { "groupid":0, "clusterid":0, "srcaddr":44052, "srcendpoint":1, "dstendpoint":1, "wasbroadcast":0, "linkquality":78, "securityuse":0, "timestamp":2206697, "transseqnumber":0, "len":55, "data":bytes([24,2,1,5,0,0,66,23,84,82,65,68,70,82,73,32,119,105,114,101,108,101,115,115,32,100,105,109,109,101,114,4,0,0,66,14,73,75,69,65,32,111,102,32,83,119,101,100,101,110,7,0,0,48,3]) } obj = ZpiObject.from_command( t.CommandType.AREQ, t.Subsystem.AF, 'incomingMsg', payload ) assert "AREQ AF incomingMsg tsn: None {'groupid': 0, 'clusterid': 0, 'srcaddr': 44052, " \ "'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 78, " \ "'securityuse': 0, 'timestamp': 2206697, 'transseqnumber': 0, 'len': 55, " \ "'data': b'\\x18\\x02\\x01\\x05\\x00\\x00B\\x17TRADFRI wireless dimmer\\x04\\x00\\x00B\\x0eIKEA of Sweden\\x07\\x00\\x000\\x03'}" == str(obj)
async def request(self, subsystem, command, payload, waiter_id=None, expected_status=None): obj = ZpiObject.from_command(subsystem, command, payload) return await self.request_raw(obj, waiter_id, expected_status)