3
3
from unittest import mock
4
4
5
5
import pytest
6
- from zigpy .types import EUI64
6
+ from zigpy .types import EUI64 , Group , BroadcastAddress
7
7
import zigpy .zdo .types as zdo_t
8
+ from zigpy .zcl .clusters .general import Groups
8
9
9
10
from zigpy_cc import types as t
10
11
from zigpy_cc .api import API
@@ -26,6 +27,7 @@ def app():
26
27
app = application .ControllerApplication (APP_CONFIG )
27
28
app ._api = API (APP_CONFIG [config .CONF_DEVICE ])
28
29
app ._api .set_application (app )
30
+ app ._semaphore = asyncio .Semaphore ()
29
31
return app
30
32
31
33
@@ -64,39 +66,6 @@ def addr_nwk_and_ieee(nwk, ieee):
64
66
return addr
65
67
66
68
67
- """
68
- DEBUG:zigpy_cc.api:--> AREQ ZDO leaveInd {'srcaddr': 406, 'extaddr': '0x07a3c302008d1500', 'request': 0, 'removechildren': 0, 'rejoin': 0}
69
- DEBUG:zigpy_cc.api:--> AREQ ZDO tcDeviceInd {'nwkaddr': 11938, 'extaddr': '0x07a3c302008d1500', 'parentaddr': 0}
70
- DEBUG:zigpy_cc.api:--> AREQ ZDO endDeviceAnnceInd {'srcaddr': 11938, 'nwkaddr': 11938, 'ieeeaddr': '0x07a3c302008d1500', 'capabilities': 128}
71
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 0, 'srcaddr': 11938, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 123, 'securityuse': 0, 'timestamp': 1000027, 'transseqnumber': 0, 'len': 25, 'data': bytearray(b'\x18 \x00 \n \x05 \x00 B\x12 lumi.sensor_switch')}
72
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 0, 'srcaddr': 11938, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 123, 'securityuse': 0, 'timestamp': 1000039, 'transseqnumber': 0, 'len': 7, 'data': bytearray(b'\x18 \x01 \n \x01 \x00 \n ')}
73
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 0, 'srcaddr': 11938, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 126, 'securityuse': 0, 'timestamp': 1000050, 'transseqnumber': 0, 'len': 29, 'data': bytearray(b'\x1c 4\x12 \x02 \n \x02 \xff L\x06 \x00 \x10 \x01 !\xd8 \x0b !\xa8 \x01 $\x00 \x00 \x00 \x00 \x00 !\xbd J Y')}
74
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 6595, 'relaycount': 1, 'relaylist': [30485]}
75
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 6595, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 60, 'securityuse': 0, 'timestamp': 1069473, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x94 \x00 \x00 \x00 ')}
76
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 49164, 'relaycount': 2, 'relaylist': [6595, 30485]}
77
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 49164, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 60, 'securityuse': 0, 'timestamp': 1117084, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x13 \x00 \x00 \x00 ')}
78
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 51918, 'relaycount': 0, 'relaylist': []}
79
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 51918, 'relaycount': 0, 'relaylist': []}
80
- DEBUG:zigpy_cc.api:--> AREQ ZDO endDeviceAnnceInd {'srcaddr': 53322, 'nwkaddr': 53322, 'ieeeaddr': '0x41e54b02008d1500', 'capabilities': 132}
81
- DEBUG:zigpy_cc.api:--> AREQ ZDO tcDeviceInd {'nwkaddr': 53322, 'extaddr': '0x41e54b02008d1500', 'parentaddr': 51918}
82
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 53322, 'relaycount': 1, 'relaylist': [51918]}
83
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 53322, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 39, 'securityuse': 0, 'timestamp': 1137608, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x1d \x00 \x00 \x00 ')}
84
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 44052, 'relaycount': 2, 'relaylist': [6595, 30485]}
85
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 18, 'srcaddr': 44052, 'srcendpoint': 2, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 60, 'securityuse': 0, 'timestamp': 1167545, 'transseqnumber': 0, 'len': 8, 'data': bytearray(b'\x18 E\n U\x00 !\x02 \x00 ')}
86
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 6595, 'relaycount': 1, 'relaylist': [30485]}
87
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 6595, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 57, 'securityuse': 0, 'timestamp': 1256953, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \xd1 \x00 \x00 \x00 ')}
88
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 49164, 'relaycount': 2, 'relaylist': [6595, 30485]}
89
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 49164, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 57, 'securityuse': 0, 'timestamp': 1310524, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x14 \x00 \x00 \x00 ')}
90
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 53322, 'relaycount': 1, 'relaylist': [51918]}
91
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 53322, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 39, 'securityuse': 0, 'timestamp': 1331211, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x1e \x00 \x00 \x00 ')}
92
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 6595, 'relaycount': 1, 'relaylist': [30485]}
93
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 6595, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 60, 'securityuse': 0, 'timestamp': 1444466, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x0e \x00 \x00 \x00 ')}
94
- DEBUG:zigpy_cc.api:--> AREQ ZDO srcRtgInd {'dstaddr': 49164, 'relaycount': 2, 'relaylist': [6595, 30485]}
95
- DEBUG:zigpy_cc.api:--> AREQ AF incomingMsg {'groupid': 0, 'clusterid': 10, 'srcaddr': 49164, 'srcendpoint': 1, 'dstendpoint': 1, 'wasbroadcast': 0, 'linkquality': 57, 'securityuse': 0, 'timestamp': 1504140, 'transseqnumber': 0, 'len': 5, 'data': bytearray(b'\x10 \x15 \x00 \x00 \x00 ')}
96
- DEBUG:zigpy_cc.api:--> AREQ ZDO tcDeviceInd {'nwkaddr': 49164, 'extaddr': '0x7ceb2303008d1500', 'parentaddr': 6595}
97
- """
98
-
99
-
100
69
def test_join (app ):
101
70
payload = {"nwkaddr" : 27441 , "extaddr" : "0x07a3c302008d1500" , "parentaddr" : 0 }
102
71
obj = ZpiObject (2 , 5 , "tcDeviceInd" , 202 , payload , [])
@@ -199,13 +168,58 @@ async def test_request(app: application.ControllerApplication):
199
168
)
200
169
201
170
assert len (app ._api ._waiters ) == 1
171
+ assert (
172
+ "SREQ ZDO nodeDescReq tsn: 1 {'dstaddr': 0xd04a, 'nwkaddrofinterest': 0x2ea2}"
173
+ == str (app ._api .request_raw .call_args [0 ][0 ])
174
+ )
202
175
assert res == (0 , "message send success" )
203
176
204
177
178
+ @pytest .mark .asyncio
179
+ async def test_mrequest (app : application .ControllerApplication ):
180
+ fut = asyncio .Future ()
181
+ fut .set_result (None )
182
+ app ._api .request_raw = mock .MagicMock (return_value = fut )
183
+
184
+ # multicast (0x0002, 260, 6, 1, 39, b"\x01'\x00", 0, 3)
185
+ res = await app .mrequest (Group (2 ), 260 , Groups .cluster_id , 1 , 39 , b"\x01 '\x00 " )
186
+
187
+ assert 1 == len (app ._api ._waiters )
188
+ assert (
189
+ "SREQ AF dataRequestExt tsn: 39 {'dstaddrmode': <AddressMode.ADDR_GROUP: 1>, "
190
+ "'dstaddr': 0x0002, 'destendpoint': 255, 'dstpanid': 0, "
191
+ "'srcendpoint': 1, 'clusterid': 4, 'transid': 39, 'options': 0, 'radius': 30, 'len': 3, "
192
+ "'data': b\" \\ x01'\\ x00\" }" == str (app ._api .request_raw .call_args [0 ][0 ])
193
+ )
194
+ assert (0 , "message send success" ) == res
195
+
196
+
197
+ @pytest .mark .asyncio
198
+ async def test_broadcast (app : application .ControllerApplication ):
199
+ fut = asyncio .Future ()
200
+ fut .set_result (None )
201
+ app ._api .request_raw = mock .MagicMock (return_value = fut )
202
+
203
+ # broadcast (0, 54, 0, 0, 0, 0, 45, b'-<\x00', <BroadcastAddress.ALL_ROUTERS_AND_COORDINATOR: 65532>)
204
+ res = await app .broadcast (
205
+ 0 , 54 , 0 , 0 , 0 , 0 , 45 , b"-<\x00 " , BroadcastAddress .ALL_ROUTERS_AND_COORDINATOR
206
+ )
207
+
208
+ assert 0 == len (app ._api ._waiters )
209
+ assert (
210
+ "SREQ ZDO mgmtPermitJoinReq tsn: 45 {'addrmode': <AddressMode.ADDR_BROADCAST: 15>, "
211
+ "'dstaddr': 0xfffc, 'duration': 60, 'tcsignificance': 0}"
212
+ == str (app ._api .request_raw .call_args [0 ][0 ])
213
+ )
214
+ assert (0 , "broadcast send success" ) == res
215
+
216
+
205
217
"""
206
218
zigpy_cc.api DEBUG <-- SREQ ZDO nodeDescReq {'dstaddr': 53322, 'nwkaddrofinterest': 0}
207
219
zigpy_cc.api DEBUG --> SRSP ZDO nodeDescReq {'status': 0}
208
- zigpy_cc.api DEBUG --> AREQ ZDO nodeDescRsp {'srcaddr': 53322, 'status': 128, 'nwkaddr': 0, 'logicaltype_cmplxdescavai_userdescavai': 0, 'apsflags_freqband': 0, 'maccapflags': 0, 'manufacturercode': 0, 'maxbuffersize': 0, 'maxintransfersize': 0, 'servermask': 0, 'maxouttransfersize': 0, 'descriptorcap': 0}
220
+ zigpy_cc.api DEBUG --> AREQ ZDO nodeDescRsp {'srcaddr': 53322, 'status': 128, 'nwkaddr': 0,
221
+ 'logicaltype_cmplxdescavai_userdescavai': 0, 'apsflags_freqband': 0, 'maccapflags': 0, 'manufacturercode': 0,
222
+ 'maxbuffersize': 0, 'maxintransfersize': 0, 'servermask': 0, 'maxouttransfersize': 0, 'descriptorcap': 0}
209
223
"""
210
224
211
225
0 commit comments