def test_from_cluster_id_ZCL(): profile = 260 obj = ZpiObject.from_cluster(t.NWK(53322), profile, 0, 1, 1, 1, b'\x00\x0b\x00\x04\x00\x05\x00', 123) assert "SREQ AF dataRequest tsn: 1 {'dstaddr': 53322, 'destendpoint': 1, 'srcendpoint': 1, " \ "'clusterid': 0, 'transid': 123, 'options': 0, 'radius': 30, 'len': 7, " \ "'data': b'\\x00\\x0b\\x00\\x04\\x00\\x05\\x00'}" == str(obj)
def test_bind_req(): ''' zigpy_cc.zigbee.application DEBUG request ( 0xbd8b, 0, <ZDOCmd.Bind_req: 0x0021>, 0, 0, 1, b"\x01<x'\xfe\xffW\x0b\x00\x01\x08\x00\x03\x0c%\xed\x18\x00K\x12\x00\x01", True, False) zigpy_cc.api DEBUG waiting for 1 bindReq zigpy_cc.api DEBUG --> SREQ ZDO bindReq tsn: 1 { 'dstaddr': 0xbd8b, '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} zigpy_cc.uart DEBUG Send: b"\xfe\x17%!\x8b\xbd<x'\xfe\xffW\x0b\x00\x01\x08\x00\x03\x0c%\xed\x18\x00K\x12\x00\x01\x95" ''' data = b"\x02<x'\xfe\xffW\x0b\x00\x01\x08\x00\x03\x0c%\xed\x18\x00K\x12\x00\x01" obj = ZpiObject.from_cluster( NWK(0x6292), 0, 0x0021, 0, 0, 2, data, 123 ) assert ( "SREQ ZDO bindReq tsn: 2 {" "'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() )
def test_from_cluster_id(): profile = 0 obj = ZpiObject.from_cluster(NWK(53322), profile, ZDOCmd.Node_Desc_req, 0, 0, 0, b"\x03\x4a\xd0", 32) assert ( "SREQ ZDO nodeDescReq tsn: 0 {'dstaddr': 0xd04a, 'nwkaddrofinterest': 0xd04a}" == str(obj))
async def broadcast( self, profile, cluster, src_ep, dst_ep, grpid, radius, sequence, data, broadcast_address=zigpy.types.BroadcastAddress.RX_ON_WHEN_IDLE, ): LOGGER.debug( "broadcast %s", ( profile, cluster, src_ep, dst_ep, grpid, radius, sequence, data, broadcast_address, ), ) try: obj = ZpiObject.from_cluster( broadcast_address, profile, cluster, src_ep, dst_ep, sequence, data, radius=radius, addr_mode=AddressMode.ADDR_16BIT, ) async with self._semaphore: await self._api.request_raw(obj) """ As a broadcast command is not confirmed and thus immediately returns (contrary to network address requests) we will give the command some time to 'settle' in the network. """ await asyncio.sleep(0.2) except CommandError as ex: return ( ex.status, "Couldn't enqueue send data request for broadcast: {}".format( ex), ) return 0, "broadcast send success"
async def mrequest(self, group_id, profile, cluster, src_ep, sequence, data, *, hops=0, non_member_radius=3): """Submit and send data out as a multicast transmission. :param group_id: destination multicast address :param profile: Zigbee Profile ID to use for outgoing message :param cluster: cluster id where the message is being sent :param src_ep: source endpoint id :param sequence: transaction sequence number of the message :param data: Zigbee message payload :param hops: the message will be delivered to all nodes within this number of hops of the sender. A value of zero is converted to MAX_HOPS :param non_member_radius: the number of hops that the message will be forwarded by devices that are not members of the group. A value of 7 or greater is treated as infinite :returns: return a tuple of a status and an error_message. Original requestor has more context to provide a more meaningful error message """ req_id = self.get_sequence() LOGGER.debug( "multicast %s", ( group_id, profile, cluster, src_ep, sequence, data, hops, non_member_radius, ), ) try: obj = ZpiObject.from_cluster(group_id, profile, cluster, src_ep, src_ep, sequence, data, req_id) await self._api.request_raw(obj) except CommandError as ex: return ex.status, "Couldn't enqueue send data multicast: {}".format( ex) return 0, "message send success"
async def broadcast( self, profile, cluster, src_ep, dst_ep, grpid, radius, sequence, data, broadcast_address=zigpy.types.BroadcastAddress.RX_ON_WHEN_IDLE, ): req_id = self.get_sequence() LOGGER.debug( "broadcast %s", ( profile, cluster, src_ep, dst_ep, grpid, radius, sequence, data, broadcast_address, ), ) try: obj = ZpiObject.from_cluster( broadcast_address, profile, cluster, src_ep, dst_ep, sequence, data, req_id, radius=radius, ) await self._api.request_raw(obj) except CommandError as ex: return ( ex.status, "Couldn't enqueue send data request for broadcast: {}".format( ex), ) return 0, "broadcast send success"
async def request( self, device, profile, cluster, src_ep, dst_ep, sequence, data, expect_reply=True, use_ieee=False, ): LOGGER.debug( "request %s", ( device.nwk, profile, cluster, src_ep, dst_ep, sequence, data, expect_reply, use_ieee, ), ) try: obj = ZpiObject.from_cluster(device.nwk, profile, cluster, src_ep, dst_ep, sequence, data) waiter_id = None if expect_reply: waiter = self._api.create_response_waiter(obj, sequence) if waiter: waiter_id = waiter.id async with self._semaphore: await self._api.request_raw(obj, waiter_id) except CommandError as ex: return ex.status, "Couldn't enqueue send data request: {}".format( ex) return 0, "message send success"
async def mrequest(self, group_id, profile, cluster, src_ep, sequence, data, *, hops=0, non_member_radius=3): """Submit and send data out as a multicast transmission. :param group_id: destination multicast address :param profile: Zigbee Profile ID to use for outgoing message :param cluster: cluster id where the message is being sent :param src_ep: source endpoint id :param sequence: transaction sequence number of the message :param data: Zigbee message payload :param hops: the message will be delivered to all nodes within this number of hops of the sender. A value of zero is converted to MAX_HOPS :param non_member_radius: the number of hops that the message will be forwarded by devices that are not members of the group. A value of 7 or greater is treated as infinite :returns: return a tuple of a status and an error_message. Original requestor has more context to provide a more meaningful error message """ LOGGER.debug( "multicast %s", ( group_id, profile, cluster, src_ep, sequence, data, hops, non_member_radius, ), ) try: obj = ZpiObject.from_cluster( group_id, profile, cluster, src_ep or 1, 0xFF, sequence, data, addr_mode=AddressMode.ADDR_GROUP, ) waiter_id = None waiter = self._api.create_response_waiter(obj, sequence) if waiter: waiter_id = waiter.id async with self._semaphore: await self._api.request_raw(obj, waiter_id) """ As a group command is not confirmed and thus immediately returns (contrary to network address requests) we will give the command some time to 'settle' in the network. """ await asyncio.sleep(0.2) except CommandError as ex: return ex.status, "Couldn't enqueue send data multicast: {}".format( ex) return 0, "message send success"
async def request( self, device, profile, cluster, src_ep, dst_ep, sequence, data, expect_reply=True, use_ieee=False, ): req_id = self.get_sequence() LOGGER.debug( "Sending Zigbee request with tsn %s under %s request id, data: %s", sequence, req_id, data, ) with self._pending.new(req_id) as req: try: # TODO FIX ERROR """ zigpy_cc.api DEBUG --> AREQ ZDO simpleDescRsp {'srcaddr': 6604, 'status': 0, 'nwkaddr': 6604, 'len': 30, 'endpoint': 1, 'profileid': 260, 'deviceid': 260, 'deviceversion': 1, 'numinclusters': 4, 'inclusterlist': [0, 3, 65535, 25], 'numoutclusters': 7, 'outclusterlist': [0, 4, 3, 6, 8, 5, 25]} zigpy_cc.zigbee.application INFO REPLY for 9 simpleDescRsp zigpy_cc.zigbee.application INFO handle_message simpleDescRsp zigpy.endpoint INFO [0x19cc:1] Discovered endpoint information: <SimpleDescriptor endpoint=1 profile=260 device_type=260 device_version=1 input_clusters=[0, 3, 65535, 25] output_clusters=[0, 4, 3, 6, 8, 5, 25]> zigpy.device DEBUG [0x19cc] Extending timeout for 0x0b request zigpy_cc.zigbee.application DEBUG Sending Zigbee request with tsn 11 under 12 request id, data: b'\x00\x0b\x00\x04\x00\x05\x00' zigpy_cc.zigbee.application ERROR from_cluster failed ('Not implemented', 0) Traceback (most recent call last): File "/home/sanya/repos/zigpy/zigpy-cc/zigpy_cc/zigbee/application.py", line 155, in request obj = ZpiObject.from_cluster(device.nwk, cluster, data) File "/home/sanya/repos/zigpy/zigpy-cc/zigpy_cc/zpi_object.py", line 54, in from_cluster subsystem = Subsystem.from_cluster(cluster) File "/home/sanya/repos/zigpy/zigpy-cc/zigpy_cc/types.py", line 339, in from_cluster raise Exception("Not implemented", cluster) Exception: ('Not implemented', 0) profile 260 cluster 0 src_ep 1 dst_ep 1 sequence 1 data b'\x00\x0b\x00\x04\x00\x05\x00' """ obj = ZpiObject.from_cluster( device.nwk, profile, cluster, src_ep, dst_ep, sequence, data, req_id ) except Exception as e: LOGGER.exception('from_cluster failed %s', e) print('profile', profile) print('cluster', cluster) print('src_ep', src_ep) print('dst_ep', dst_ep) print('sequence', dst_ep) print('data', data) traceback.print_stack() raise e try: if expect_reply: self._api.create_response_waiter(obj, sequence) await self._api.request_raw(obj) except zigpy_cc.exception.CommandError as ex: return ex.status, "Couldn't enqueue send data request: {}".format(ex) return 0, "message send success"