Skip to content

Commit b609de9

Browse files
committed
Drop the Commands suffix from all command classes
1 parent abc0949 commit b609de9

File tree

17 files changed

+287
-346
lines changed

17 files changed

+287
-346
lines changed

tests/test_api.py

Lines changed: 103 additions & 119 deletions
Large diffs are not rendered by default.

tests/test_application.py

Lines changed: 65 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ def __init__(self, *args, **kwargs):
5454
super().__init__(*args, **kwargs)
5555

5656
# We just respond to pings, nothing more
57-
self.callback_for_response(
58-
c.SysCommands.Ping.Req(), lambda r: self.ping_replier(r)
59-
)
57+
self.callback_for_response(c.Sys.Ping.Req(), lambda r: self.ping_replier(r))
6058

6159
def reply_once_to(self, request, responses):
6260
called_future = asyncio.get_running_loop().create_future()
@@ -95,7 +93,7 @@ async def callback():
9593
return callback
9694

9795
def ping_replier(self, request):
98-
self.send(c.SysCommands.Ping.Rsp(Capabilities=t.MTCapabilities(1625)))
96+
self.send(c.Sys.Ping.Rsp(Capabilities=t.MTCapabilities(1625)))
9997

10098
def send(self, response):
10199
self._uart.send(response.to_frame())
@@ -140,9 +138,9 @@ def application(znp_server):
140138

141139
# Handle the entire startup sequence
142140
znp_server.reply_to(
143-
request=c.SysCommands.ResetReq.Req(Type=t.ResetType.Soft),
141+
request=c.Sys.ResetReq.Req(Type=t.ResetType.Soft),
144142
responses=[
145-
c.SysCommands.ResetInd.Callback(
143+
c.Sys.ResetInd.Callback(
146144
Reason=t.ResetReason.PowerUp,
147145
TransportRev=2,
148146
ProductId=1,
@@ -154,32 +152,32 @@ def application(znp_server):
154152
)
155153

156154
znp_server.reply_to(
157-
request=c.ZDOCommands.ActiveEpReq.Req(DstAddr=0x0000, NWKAddrOfInterest=0x0000),
155+
request=c.ZDO.ActiveEpReq.Req(DstAddr=0x0000, NWKAddrOfInterest=0x0000),
158156
responses=[
159-
c.ZDOCommands.ActiveEpReq.Rsp(Status=t.Status.Success),
160-
c.ZDOCommands.ActiveEpRsp.Callback(
157+
c.ZDO.ActiveEpReq.Rsp(Status=t.Status.Success),
158+
c.ZDO.ActiveEpRsp.Callback(
161159
Src=0x0000, Status=t.ZDOStatus.SUCCESS, NWK=0x0000, ActiveEndpoints=[]
162160
),
163161
],
164162
)
165163

166164
znp_server.reply_to(
167-
request=c.AFCommands.Register.Req(partial=True),
168-
responses=[c.AFCommands.Register.Rsp(Status=t.Status.Success)],
165+
request=c.AF.Register.Req(partial=True),
166+
responses=[c.AF.Register.Rsp(Status=t.Status.Success)],
169167
)
170168

171169
znp_server.reply_to(
172-
request=c.APPConfigCommands.BDBStartCommissioning.Req(
170+
request=c.AppConfig.BDBStartCommissioning.Req(
173171
Mode=c.app_config.BDBCommissioningMode.NetworkFormation
174172
),
175173
responses=[
176-
c.APPConfigCommands.BDBStartCommissioning.Rsp(Status=t.Status.Success),
177-
c.APPConfigCommands.BDBCommissioningNotification.Callback(
174+
c.AppConfig.BDBStartCommissioning.Rsp(Status=t.Status.Success),
175+
c.AppConfig.BDBCommissioningNotification.Callback(
178176
Status=c.app_config.BDBCommissioningStatus.Success,
179177
Mode=c.app_config.BDBCommissioningMode.NwkSteering,
180178
RemainingModes=c.app_config.BDBRemainingCommissioningModes.NONE,
181179
),
182-
c.APPConfigCommands.BDBCommissioningNotification.Callback(
180+
c.AppConfig.BDBCommissioningNotification.Callback(
183181
Status=c.app_config.BDBCommissioningStatus.NoNetwork,
184182
Mode=c.app_config.BDBCommissioningMode.NwkSteering,
185183
RemainingModes=c.app_config.BDBRemainingCommissioningModes.NONE,
@@ -196,8 +194,8 @@ def application(znp_server):
196194
NwkNvIds.NWK_CHILD_AGE_ENABLE,
197195
]:
198196
znp_server.reply_to(
199-
request=c.SysCommands.OSALNVWrite.Req(Id=nvid, Offset=0, partial=True),
200-
responses=[c.SysCommands.OSALNVWrite.Rsp(Status=t.Status.Success)],
197+
request=c.Sys.OSALNVWrite.Req(Id=nvid, Offset=0, partial=True),
198+
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.Success)],
201199
)
202200

203201
return app, znp_server
@@ -219,9 +217,7 @@ def register_endpoint(request):
219217
if num_endpoints < 0:
220218
raise RuntimeError("Too many endpoints registered")
221219

222-
znp_server.callback_for_response(
223-
c.AFCommands.Register.Req(partial=True), register_endpoint
224-
)
220+
znp_server.callback_for_response(c.AF.Register.Req(partial=True), register_endpoint)
225221

226222
await app.startup(auto_form=False)
227223

@@ -233,8 +229,8 @@ async def test_application_startup_tx_power(application):
233229
app, znp_server = application
234230

235231
set_tx_power = znp_server.reply_once_to(
236-
request=c.SysCommands.SetTxPower.Req(TXPower=19),
237-
responses=[c.SysCommands.SetTxPower.Rsp(Status=t.Status.Success)],
232+
request=c.Sys.SetTxPower.Req(TXPower=19),
233+
responses=[c.Sys.SetTxPower.Rsp(Status=t.Status.Success)],
238234
)
239235

240236
app.update_config({conf.CONF_ZNP_CONFIG: {conf.CONF_TX_POWER: 19}})
@@ -249,25 +245,19 @@ async def test_permit_join(application):
249245

250246
# Handle the ZDO broadcast sent by Zigpy
251247
data_req_sent = znp_server.reply_once_to(
252-
request=c.AFCommands.DataRequestExt.Req(
253-
partial=True, SrcEndpoint=0, DstEndpoint=0
254-
),
248+
request=c.AF.DataRequestExt.Req(partial=True, SrcEndpoint=0, DstEndpoint=0),
255249
responses=[
256-
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
257-
c.AFCommands.DataConfirm.Callback(
258-
Status=t.Status.Success, Endpoint=0, TSN=1
259-
),
250+
c.AF.DataRequestExt.Rsp(Status=t.Status.Success),
251+
c.AF.DataConfirm.Callback(Status=t.Status.Success, Endpoint=0, TSN=1),
260252
],
261253
)
262254

263255
# Handle the permit join request sent by us
264256
permit_join_sent = znp_server.reply_once_to(
265-
request=c.ZDOCommands.MgmtPermitJoinReq.Req(partial=True),
257+
request=c.ZDO.MgmtPermitJoinReq.Req(partial=True),
266258
responses=[
267-
c.ZDOCommands.MgmtPermitJoinReq.Rsp(Status=t.Status.Success),
268-
c.ZDOCommands.MgmtPermitJoinRsp.Callback(
269-
Src=0x0000, Status=t.ZDOStatus.SUCCESS
270-
),
259+
c.ZDO.MgmtPermitJoinReq.Rsp(Status=t.Status.Success),
260+
c.ZDO.MgmtPermitJoinRsp.Callback(Src=0x0000, Status=t.ZDOStatus.SUCCESS),
271261
],
272262
)
273263

@@ -284,25 +274,19 @@ async def test_permit_join_failure(application):
284274

285275
# Handle the ZDO broadcast sent by Zigpy
286276
data_req_sent = znp_server.reply_once_to(
287-
request=c.AFCommands.DataRequestExt.Req(
288-
partial=True, SrcEndpoint=0, DstEndpoint=0
289-
),
277+
request=c.AF.DataRequestExt.Req(partial=True, SrcEndpoint=0, DstEndpoint=0),
290278
responses=[
291-
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
292-
c.AFCommands.DataConfirm.Callback(
293-
Status=t.Status.Success, Endpoint=0, TSN=1
294-
),
279+
c.AF.DataRequestExt.Rsp(Status=t.Status.Success),
280+
c.AF.DataConfirm.Callback(Status=t.Status.Success, Endpoint=0, TSN=1),
295281
],
296282
)
297283

298284
# Handle the permit join request sent by us
299285
permit_join_sent = znp_server.reply_once_to(
300-
request=c.ZDOCommands.MgmtPermitJoinReq.Req(partial=True),
286+
request=c.ZDO.MgmtPermitJoinReq.Req(partial=True),
301287
responses=[
302-
c.ZDOCommands.MgmtPermitJoinReq.Rsp(Status=t.Status.Success),
303-
c.ZDOCommands.MgmtPermitJoinRsp.Callback(
304-
Src=0xFFFF, Status=t.ZDOStatus.TIMEOUT
305-
),
288+
c.ZDO.MgmtPermitJoinReq.Rsp(Status=t.Status.Success),
289+
c.ZDO.MgmtPermitJoinRsp.Callback(Src=0xFFFF, Status=t.ZDOStatus.TIMEOUT),
306290
],
307291
)
308292

@@ -323,9 +307,7 @@ async def test_on_zdo_relays_message_callback(application, mocker):
323307
device = mocker.Mock()
324308
mocker.patch.object(app, "get_device", return_value=device)
325309

326-
znp_server.send(
327-
c.ZDOCommands.SrcRtgInd.Callback(DstAddr=0x1234, Relays=[0x5678, 0xABCD])
328-
)
310+
znp_server.send(c.ZDO.SrcRtgInd.Callback(DstAddr=0x1234, Relays=[0x5678, 0xABCD]))
329311
assert device.relays == [0x5678, 0xABCD]
330312

331313

@@ -340,7 +322,7 @@ async def test_on_zdo_device_announce(application, mocker):
340322
ieee = t.EUI64(range(8))
341323

342324
znp_server.send(
343-
c.ZDOCommands.EndDeviceAnnceInd.Callback(
325+
c.ZDO.EndDeviceAnnceInd.Callback(
344326
Src=0x0001, NWK=nwk, IEEE=ieee, Capabilities=c.zdo.MACCapabilities.Router
345327
)
346328
)
@@ -357,9 +339,7 @@ async def test_on_zdo_device_join(application, mocker):
357339
nwk = 0x1234
358340
ieee = t.EUI64(range(8))
359341

360-
znp_server.send(
361-
c.ZDOCommands.TCDevInd.Callback(SrcNwk=nwk, SrcIEEE=ieee, ParentNwk=0x0001)
362-
)
342+
znp_server.send(c.ZDO.TCDevInd.Callback(SrcNwk=nwk, SrcIEEE=ieee, ParentNwk=0x0001))
363343
app.handle_join.assert_called_once_with(nwk=nwk, ieee=ieee, parent_nwk=0x0001)
364344

365345

@@ -374,7 +354,7 @@ async def test_on_zdo_device_leave_callback(application, mocker):
374354
ieee = t.EUI64(range(8))
375355

376356
znp_server.send(
377-
c.ZDOCommands.LeaveInd.Callback(
357+
c.ZDO.LeaveInd.Callback(
378358
NWK=nwk, IEEE=ieee, Request=False, Remove=False, Rejoin=False
379359
)
380360
)
@@ -392,7 +372,7 @@ async def test_on_af_message_callback(application, mocker):
392372
)
393373
mocker.patch.object(app, "handle_message")
394374

395-
af_message = c.AFCommands.IncomingMsg.Callback(
375+
af_message = c.AF.IncomingMsg.Callback(
396376
GroupId=1,
397377
ClusterId=2,
398378
SrcAddr=0xABCD,
@@ -539,12 +519,12 @@ async def test_zdo_request_interception(application, mocker):
539519

540520
# Send back a request response
541521
active_ep_req = znp_server.reply_once_to(
542-
request=c.ZDOCommands.SimpleDescReq.Req(
522+
request=c.ZDO.SimpleDescReq.Req(
543523
DstAddr=device.nwk, NWKAddrOfInterest=device.nwk, Endpoint=1
544524
),
545525
responses=[
546-
c.ZDOCommands.SimpleDescReq.Rsp(Status=t.Status.Success),
547-
c.ZDOCommands.SimpleDescRsp.Callback(
526+
c.ZDO.SimpleDescReq.Rsp(Status=t.Status.Success),
527+
c.ZDO.SimpleDescRsp.Callback(
548528
Src=device.nwk,
549529
Status=t.ZDOStatus.SUCCESS,
550530
NWK=device.nwk,
@@ -593,7 +573,7 @@ async def test_zigpy_request(application, mocker):
593573

594574
# Respond to a light turn on request
595575
data_req = znp_server.reply_once_to(
596-
request=c.AFCommands.DataRequestExt.Req(
576+
request=c.AF.DataRequestExt.Req(
597577
DstAddrModeAddress=t.AddrModeAddress(
598578
mode=t.AddrMode.NWK, address=device.nwk
599579
),
@@ -605,12 +585,10 @@ async def test_zigpy_request(application, mocker):
605585
partial=True,
606586
),
607587
responses=[
608-
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
609-
c.AFCommands.DataConfirm.Callback(
610-
Status=t.Status.Success, Endpoint=1, TSN=TSN,
611-
),
612-
c.ZDOCommands.SrcRtgInd.Callback(DstAddr=device.nwk, Relays=[]),
613-
c.AFCommands.IncomingMsg.Callback(
588+
c.AF.DataRequestExt.Rsp(Status=t.Status.Success),
589+
c.AF.DataConfirm.Callback(Status=t.Status.Success, Endpoint=1, TSN=TSN,),
590+
c.ZDO.SrcRtgInd.Callback(DstAddr=device.nwk, Relays=[]),
591+
c.AF.IncomingMsg.Callback(
614592
GroupId=0x0000,
615593
ClusterId=6,
616594
SrcAddr=device.nwk,
@@ -648,7 +626,7 @@ async def test_zigpy_request_failure(application, mocker):
648626

649627
# Fail to respond to a light turn on request
650628
znp_server.reply_to(
651-
request=c.AFCommands.DataRequestExt.Req(
629+
request=c.AF.DataRequestExt.Req(
652630
DstAddrModeAddress=t.AddrModeAddress(
653631
mode=t.AddrMode.NWK, address=device.nwk
654632
),
@@ -660,10 +638,8 @@ async def test_zigpy_request_failure(application, mocker):
660638
partial=True,
661639
),
662640
responses=[
663-
c.AFCommands.DataRequestExt.Rsp(Status=t.Status.Success),
664-
c.AFCommands.DataConfirm.Callback(
665-
Status=t.Status.Failure, Endpoint=1, TSN=TSN,
666-
),
641+
c.AF.DataRequestExt.Rsp(Status=t.Status.Success),
642+
c.AF.DataConfirm.Callback(Status=t.Status.Failure, Endpoint=1, TSN=TSN,),
667643
],
668644
)
669645

@@ -737,44 +713,44 @@ async def test_update_network(mocker, caplog, application):
737713
network_key = t.KeyData(range(16))
738714

739715
channels_updated = znp_server.reply_once_to(
740-
request=c.UtilCommands.SetChannels.Req(Channels=channels),
741-
responses=[c.UtilCommands.SetChannels.Rsp(Status=t.Status.Success)],
716+
request=c.Util.SetChannels.Req(Channels=channels),
717+
responses=[c.Util.SetChannels.Rsp(Status=t.Status.Success)],
742718
)
743719

744720
bdb_set_primary_channel = znp_server.reply_once_to(
745-
request=c.APPConfigCommands.BDBSetChannel.Req(IsPrimary=True, Channel=channels),
746-
responses=[c.APPConfigCommands.BDBSetChannel.Rsp(Status=t.Status.Success)],
721+
request=c.AppConfig.BDBSetChannel.Req(IsPrimary=True, Channel=channels),
722+
responses=[c.AppConfig.BDBSetChannel.Rsp(Status=t.Status.Success)],
747723
)
748724

749725
bdb_set_secondary_channel = znp_server.reply_once_to(
750-
request=c.APPConfigCommands.BDBSetChannel.Req(
726+
request=c.AppConfig.BDBSetChannel.Req(
751727
IsPrimary=False, Channel=t.Channels.NO_CHANNELS
752728
),
753-
responses=[c.APPConfigCommands.BDBSetChannel.Rsp(Status=t.Status.Success)],
729+
responses=[c.AppConfig.BDBSetChannel.Rsp(Status=t.Status.Success)],
754730
)
755731

756732
set_pan_id = znp_server.reply_once_to(
757-
request=c.UtilCommands.SetPanId.Req(PanId=pan_id),
758-
responses=[c.UtilCommands.SetPanId.Rsp(Status=t.Status.Success)],
733+
request=c.Util.SetPanId.Req(PanId=pan_id),
734+
responses=[c.Util.SetPanId.Rsp(Status=t.Status.Success)],
759735
)
760736

761737
set_extended_pan_id = znp_server.reply_once_to(
762-
request=c.SysCommands.OSALNVWrite.Req(
738+
request=c.Sys.OSALNVWrite.Req(
763739
Id=NwkNvIds.EXTENDED_PAN_ID, Offset=0, Value=extended_pan_id.serialize()
764740
),
765-
responses=[c.SysCommands.OSALNVWrite.Rsp(Status=t.Status.Success)],
741+
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.Success)],
766742
)
767743

768744
set_network_key_util = znp_server.reply_once_to(
769-
request=c.UtilCommands.SetPreConfigKey.Req(PreConfigKey=network_key),
770-
responses=[c.UtilCommands.SetPreConfigKey.Rsp(Status=t.Status.Success)],
745+
request=c.Util.SetPreConfigKey.Req(PreConfigKey=network_key),
746+
responses=[c.Util.SetPreConfigKey.Rsp(Status=t.Status.Success)],
771747
)
772748

773749
set_network_key_nvram = znp_server.reply_once_to(
774-
request=c.SysCommands.OSALNVWrite.Req(
750+
request=c.Sys.OSALNVWrite.Req(
775751
Id=NwkNvIds.PRECFGKEYS_ENABLE, Offset=0, Value=t.Bool(True).serialize()
776752
),
777-
responses=[c.SysCommands.OSALNVWrite.Rsp(Status=t.Status.Success)],
753+
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.Success)],
778754
)
779755

780756
# But it does succeed with a warning if you explicitly allow it
@@ -840,16 +816,16 @@ async def test_force_remove(application, mocker):
840816

841817
# Reply to zigpy's leave request
842818
bad_mgmt_leave_req = znp_server.reply_once_to(
843-
request=c.ZDOCommands.MgmtLeaveReq.Req(DstAddr=device.nwk, partial=True),
844-
responses=[c.ZDOCommands.MgmtLeaveReq.Rsp(Status=t.Status.Failure)],
819+
request=c.ZDO.MgmtLeaveReq.Req(DstAddr=device.nwk, partial=True),
820+
responses=[c.ZDO.MgmtLeaveReq.Rsp(Status=t.Status.Failure)],
845821
)
846822

847823
# Reply to our own leave request
848824
good_mgmt_leave_req = znp_server.reply_once_to(
849-
request=c.ZDOCommands.MgmtLeaveReq.Req(DstAddr=0x0000, partial=True),
825+
request=c.ZDO.MgmtLeaveReq.Req(DstAddr=0x0000, partial=True),
850826
responses=[
851-
c.ZDOCommands.MgmtLeaveReq.Rsp(Status=t.Status.Success),
852-
c.ZDOCommands.LeaveInd.Callback(
827+
c.ZDO.MgmtLeaveReq.Rsp(Status=t.Status.Success),
828+
c.ZDO.LeaveInd.Callback(
853829
NWK=device.nwk,
854830
IEEE=device.ieee,
855831
Remove=False,

0 commit comments

Comments
 (0)