Skip to content

Commit 87dd436

Browse files
committed
Uppercase SYS commands
1 parent 7916e25 commit 87dd436

File tree

8 files changed

+145
-145
lines changed

8 files changed

+145
-145
lines changed

tests/test_api.py

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

tests/test_application.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +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(c.Sys.Ping.Req(), lambda r: self.ping_replier(r))
57+
self.callback_for_response(c.SYS.Ping.Req(), lambda r: self.ping_replier(r))
5858

5959
def reply_once_to(self, request, responses):
6060
called_future = asyncio.get_running_loop().create_future()
@@ -101,7 +101,7 @@ async def callback(request):
101101
return callback
102102

103103
def ping_replier(self, request):
104-
self.send(c.Sys.Ping.Rsp(Capabilities=t.MTCapabilities(1625)))
104+
self.send(c.SYS.Ping.Rsp(Capabilities=t.MTCapabilities(1625)))
105105

106106
def send(self, response):
107107
self._uart.send(response.to_frame())
@@ -146,9 +146,9 @@ def application(znp_server):
146146

147147
# Handle the entire startup sequence
148148
znp_server.reply_to(
149-
request=c.Sys.ResetReq.Req(Type=t.ResetType.Soft),
149+
request=c.SYS.ResetReq.Req(Type=t.ResetType.Soft),
150150
responses=[
151-
c.Sys.ResetInd.Callback(
151+
c.SYS.ResetInd.Callback(
152152
Reason=t.ResetReason.PowerUp,
153153
TransportRev=2,
154154
ProductId=1,
@@ -233,13 +233,13 @@ def on_endpoint_deletion(req):
233233
NwkNvIds.NWK_CHILD_AGE_ENABLE,
234234
]:
235235
znp_server.reply_to(
236-
request=c.Sys.OSALNVWrite.Req(Id=nvid, Offset=0, partial=True),
237-
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
236+
request=c.SYS.OSALNVWrite.Req(Id=nvid, Offset=0, partial=True),
237+
responses=[c.SYS.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
238238
)
239239

240240
znp_server.reply_to(
241-
request=c.Sys.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
242-
responses=[c.Sys.OSALNVRead.Rsp(Status=t.Status.SUCCESS, Value=b"\x55")],
241+
request=c.SYS.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
242+
responses=[c.SYS.OSALNVRead.Rsp(Status=t.Status.SUCCESS, Value=b"\x55")],
243243
)
244244

245245
znp_server.reply_to(
@@ -284,20 +284,20 @@ async def test_application_startup_failure(application):
284284
app, znp_server = application
285285

286286
# Prevent the fixture's default response
287-
znp_server._response_listeners[c.Sys.OSALNVRead.Req.header].clear()
287+
znp_server._response_listeners[c.SYS.OSALNVRead.Req.header].clear()
288288

289289
znp_server.reply_once_to(
290-
request=c.Sys.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
291-
responses=[c.Sys.OSALNVRead.Rsp(Status=t.Status.INVALID_PARAMETER, Value=b"")],
290+
request=c.SYS.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
291+
responses=[c.SYS.OSALNVRead.Rsp(Status=t.Status.INVALID_PARAMETER, Value=b"")],
292292
)
293293

294294
# We cannot start the application if Z-Stack is not configured and without auto_form
295295
with pytest.raises(RuntimeError):
296296
await app.startup(auto_form=False)
297297

298298
znp_server.reply_once_to(
299-
request=c.Sys.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
300-
responses=[c.Sys.OSALNVRead.Rsp(Status=t.Status.SUCCESS, Value=b"\x00")],
299+
request=c.SYS.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
300+
responses=[c.SYS.OSALNVRead.Rsp(Status=t.Status.SUCCESS, Value=b"\x00")],
301301
)
302302

303303
with pytest.raises(RuntimeError):
@@ -309,8 +309,8 @@ async def test_application_startup_tx_power(application):
309309
app, znp_server = application
310310

311311
set_tx_power = znp_server.reply_once_to(
312-
request=c.Sys.SetTxPower.Req(TXPower=19),
313-
responses=[c.Sys.SetTxPower.Rsp(Status=t.Status.SUCCESS)],
312+
request=c.SYS.SetTxPower.Req(TXPower=19),
313+
responses=[c.SYS.SetTxPower.Rsp(Status=t.Status.SUCCESS)],
314314
)
315315

316316
app.update_config({conf.CONF_ZNP_CONFIG: {conf.CONF_TX_POWER: 19}})
@@ -818,10 +818,10 @@ async def test_update_network(mocker, caplog, application):
818818
)
819819

820820
set_extended_pan_id = znp_server.reply_once_to(
821-
request=c.Sys.OSALNVWrite.Req(
821+
request=c.SYS.OSALNVWrite.Req(
822822
Id=NwkNvIds.EXTENDED_PAN_ID, Offset=0, Value=extended_pan_id.serialize()
823823
),
824-
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
824+
responses=[c.SYS.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
825825
)
826826

827827
set_network_key_util = znp_server.reply_once_to(
@@ -830,10 +830,10 @@ async def test_update_network(mocker, caplog, application):
830830
)
831831

832832
set_network_key_nvram = znp_server.reply_once_to(
833-
request=c.Sys.OSALNVWrite.Req(
833+
request=c.SYS.OSALNVWrite.Req(
834834
Id=NwkNvIds.PRECFGKEYS_ENABLE, Offset=0, Value=t.Bool(True).serialize()
835835
),
836-
responses=[c.Sys.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
836+
responses=[c.SYS.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)],
837837
)
838838

839839
# But it does succeed with a warning if you explicitly allow it
@@ -944,27 +944,27 @@ async def test_auto_form_necessary(application, mocker):
944944
def nvram_writer(req):
945945
nvram[req.Id] = req.Value
946946

947-
return c.Sys.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)
947+
return c.SYS.OSALNVWrite.Rsp(Status=t.Status.SUCCESS)
948948

949949
def nvram_init(req):
950950
nvram[req.Id] = req.Value
951951

952-
return c.Sys.OSALNVItemInit.Rsp(Status=t.Status.SUCCESS)
952+
return c.SYS.OSALNVItemInit.Rsp(Status=t.Status.SUCCESS)
953953

954954
# Prevent the fixture's default response
955-
znp_server._response_listeners[c.Sys.OSALNVRead.Req.header].clear()
955+
znp_server._response_listeners[c.SYS.OSALNVRead.Req.header].clear()
956956

957957
read_zstack_configured = znp_server.reply_once_to(
958-
request=c.Sys.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
959-
responses=[c.Sys.OSALNVRead.Rsp(Status=t.Status.INVALID_PARAMETER, Value=b"")],
958+
request=c.SYS.OSALNVRead.Req(Id=NwkNvIds.HAS_CONFIGURED_ZSTACK3, Offset=0),
959+
responses=[c.SYS.OSALNVRead.Rsp(Status=t.Status.INVALID_PARAMETER, Value=b"")],
960960
)
961961

962962
znp_server.reply_to(
963-
request=c.Sys.OSALNVWrite.Req(Offset=0, partial=True), responses=[nvram_writer]
963+
request=c.SYS.OSALNVWrite.Req(Offset=0, partial=True), responses=[nvram_writer]
964964
)
965965

966966
znp_server.reply_to(
967-
request=c.Sys.OSALNVItemInit.Req(partial=True), responses=[nvram_init]
967+
request=c.SYS.OSALNVItemInit.Req(partial=True), responses=[nvram_init]
968968
)
969969

970970
znp_server.reply_to(

tests/test_commands.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,22 @@ def test_commands_schema():
157157

158158
def test_command_param_binding():
159159
# No params
160-
c.Sys.Ping.Req()
160+
c.SYS.Ping.Req()
161161

162162
# Invalid param name
163163
with pytest.raises(KeyError):
164-
c.Sys.Ping.Rsp(asd=123)
164+
c.SYS.Ping.Rsp(asd=123)
165165

166166
# Valid param name
167-
c.Sys.Ping.Rsp(Capabilities=t.MTCapabilities.CAP_SYS)
167+
c.SYS.Ping.Rsp(Capabilities=t.MTCapabilities.CAP_SYS)
168168

169169
# Too many params, one valid
170170
with pytest.raises(KeyError):
171-
c.Sys.Ping.Rsp(foo="asd", Capabilities=t.MTCapabilities.CAP_SYS)
171+
c.SYS.Ping.Rsp(foo="asd", Capabilities=t.MTCapabilities.CAP_SYS)
172172

173173
# Not enough params
174174
with pytest.raises(KeyError):
175-
c.Sys.Ping.Rsp()
175+
c.SYS.Ping.Rsp()
176176

177177
# Invalid type
178178
with pytest.raises(ValueError):
@@ -198,18 +198,18 @@ def test_command_param_binding():
198198
assert t.MTCapabilities.CAP_SYS == 0x0001
199199

200200
with pytest.raises(ValueError):
201-
c.Sys.Ping.Rsp(Capabilities=0x0001)
201+
c.SYS.Ping.Rsp(Capabilities=0x0001)
202202

203203
# Parameters can be looked up by name
204-
ping_rsp = c.Sys.Ping.Rsp(Capabilities=t.MTCapabilities.CAP_SYS)
204+
ping_rsp = c.SYS.Ping.Rsp(Capabilities=t.MTCapabilities.CAP_SYS)
205205
assert ping_rsp.Capabilities == t.MTCapabilities.CAP_SYS
206206

207207
# Invalid ones cannot
208208
with pytest.raises(AttributeError):
209209
ping_rsp.Oops
210210

211211
# bytes are converted into t.ShortBytes
212-
cmd = c.Sys.NVWrite.Req(
212+
cmd = c.SYS.NVWrite.Req(
213213
SysId=0x12, ItemId=0x3456, SubId=0x7890, Offset=0x0000, Value=b"asdfoo"
214214
)
215215
assert isinstance(cmd.Value, t.ShortBytes)
@@ -281,11 +281,11 @@ def test_command_str_repr():
281281

282282

283283
def test_command_immutability():
284-
command1 = c.Sys.NVWrite.Req(
284+
command1 = c.SYS.NVWrite.Req(
285285
partial=True, SysId=None, ItemId=0x1234, SubId=None, Offset=None, Value=None
286286
)
287287

288-
command2 = c.Sys.NVWrite.Req(
288+
command2 = c.SYS.NVWrite.Req(
289289
partial=True, SysId=None, ItemId=0x1234, SubId=None, Offset=None, Value=None
290290
)
291291

@@ -311,7 +311,7 @@ def test_command_immutability():
311311

312312

313313
def test_command_serialization():
314-
command = c.Sys.NVWrite.Req(
314+
command = c.SYS.NVWrite.Req(
315315
SysId=0x12, ItemId=0x3456, SubId=0x7890, Offset=0x0000, Value=b"asdfoo"
316316
)
317317
frame = command.to_frame()
@@ -320,27 +320,27 @@ def test_command_serialization():
320320

321321
# Partial frames cannot be serialized
322322
with pytest.raises(ValueError):
323-
partial1 = c.Sys.NVWrite.Req(partial=True, SysId=0x12)
323+
partial1 = c.SYS.NVWrite.Req(partial=True, SysId=0x12)
324324
partial1.to_frame()
325325

326326
# Partial frames cannot be serialized, even if all params are filled out
327327
with pytest.raises(ValueError):
328-
partial2 = c.Sys.NVWrite.Req(
328+
partial2 = c.SYS.NVWrite.Req(
329329
partial=True, SysId=None, ItemId=0x1234, SubId=None, Offset=None, Value=None
330330
)
331331
partial2.to_frame()
332332

333333

334334
def test_command_equality():
335-
command1 = c.Sys.NVWrite.Req(
335+
command1 = c.SYS.NVWrite.Req(
336336
SysId=0x12, ItemId=0x3456, SubId=0x7890, Offset=0x00, Value=b"asdfoo"
337337
)
338338

339-
command2 = c.Sys.NVWrite.Req(
339+
command2 = c.SYS.NVWrite.Req(
340340
SysId=0x12, ItemId=0x3456, SubId=0x7890, Offset=0x00, Value=b"asdfoo"
341341
)
342342

343-
command3 = c.Sys.NVWrite.Req(
343+
command3 = c.SYS.NVWrite.Req(
344344
SysId=0xFF, ItemId=0x3456, SubId=0x7890, Offset=0x00, Value=b"asdfoo"
345345
)
346346

@@ -357,22 +357,22 @@ def test_command_equality():
357357
assert not command1.matches(command3)
358358
assert not command3.matches(command1)
359359

360-
assert not command1.matches(c.Sys.NVWrite.Req(partial=True))
361-
assert c.Sys.NVWrite.Req(partial=True).matches(command1)
360+
assert not command1.matches(c.SYS.NVWrite.Req(partial=True))
361+
assert c.SYS.NVWrite.Req(partial=True).matches(command1)
362362

363363
# parameters can be specified explicitly as None
364-
assert c.Sys.NVWrite.Req(partial=True, SubId=None).matches(command1)
365-
assert c.Sys.NVWrite.Req(partial=True, SubId=0x7890).matches(command1)
366-
assert not c.Sys.NVWrite.Req(partial=True, SubId=123).matches(command1)
364+
assert c.SYS.NVWrite.Req(partial=True, SubId=None).matches(command1)
365+
assert c.SYS.NVWrite.Req(partial=True, SubId=0x7890).matches(command1)
366+
assert not c.SYS.NVWrite.Req(partial=True, SubId=123).matches(command1)
367367

368368
# Different frame types do not match, even if they have the same structure
369-
assert not c.Sys.NVWrite.Rsp(Status=t.Status.SUCCESS).matches(
370-
c.Sys.NVDelete.Rsp(partial=True)
369+
assert not c.SYS.NVWrite.Rsp(Status=t.Status.SUCCESS).matches(
370+
c.SYS.NVDelete.Rsp(partial=True)
371371
)
372372

373373

374374
def test_command_deserialization(caplog):
375-
command = c.Sys.NVWrite.Req(
375+
command = c.SYS.NVWrite.Req(
376376
SysId=0x12, ItemId=0x3456, SubId=0x7890, Offset=0x00, Value=b"asdfoo"
377377
)
378378

@@ -394,7 +394,7 @@ def test_command_deserialization(caplog):
394394

395395
# Deserialization fails if you attempt to deserialize the wrong frame
396396
with pytest.raises(ValueError):
397-
c.Sys.NVWrite.Req.from_frame(c.Sys.Ping.Req().to_frame())
397+
c.SYS.NVWrite.Req.from_frame(c.SYS.Ping.Req().to_frame())
398398

399399

400400
def test_command_not_recognized():

tests/test_uart.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_uart_rx_basic():
2222
uart = znp_uart.ZnpMtProtocol(api)
2323
uart.connection_made(transport)
2424

25-
test_command = c.Sys.ResetInd.Callback(
25+
test_command = c.SYS.ResetInd.Callback(
2626
Reason=t.ResetReason.PowerUp,
2727
TransportRev=0x00,
2828
ProductId=0x45,
@@ -51,7 +51,7 @@ def test_uart_rx_byte_by_byte():
5151
uart = znp_uart.ZnpMtProtocol(api)
5252
uart.connection_made(transport)
5353

54-
test_command = c.Sys.ResetInd.Callback(
54+
test_command = c.SYS.ResetInd.Callback(
5555
Reason=t.ResetReason.PowerUp,
5656
TransportRev=0x00,
5757
ProductId=0x45,
@@ -75,7 +75,7 @@ def test_uart_rx_byte_by_byte_garbage():
7575
uart = znp_uart.ZnpMtProtocol(api)
7676
uart.connection_made(transport)
7777

78-
test_command = c.Sys.ResetInd.Callback(
78+
test_command = c.SYS.ResetInd.Callback(
7979
Reason=t.ResetReason.PowerUp,
8080
TransportRev=0x00,
8181
ProductId=0x45,
@@ -109,7 +109,7 @@ def test_uart_rx_big_garbage():
109109
uart = znp_uart.ZnpMtProtocol(api)
110110
uart.connection_made(transport)
111111

112-
test_command = c.Sys.ResetInd.Callback(
112+
test_command = c.SYS.ResetInd.Callback(
113113
Reason=t.ResetReason.PowerUp,
114114
TransportRev=0x00,
115115
ProductId=0x45,
@@ -142,7 +142,7 @@ def test_uart_rx_corrupted_fcs():
142142
uart = znp_uart.ZnpMtProtocol(api)
143143
uart.connection_made(transport)
144144

145-
test_command = c.Sys.ResetInd.Callback(
145+
test_command = c.SYS.ResetInd.Callback(
146146
Reason=t.ResetReason.PowerUp,
147147
TransportRev=0x00,
148148
ProductId=0x45,
@@ -167,7 +167,7 @@ def test_uart_rx_sof_stress():
167167
uart = znp_uart.ZnpMtProtocol(api)
168168
uart.connection_made(transport)
169169

170-
test_command = c.Sys.ResetInd.Callback(
170+
test_command = c.SYS.ResetInd.Callback(
171171
Reason=t.ResetReason.PowerUp,
172172
TransportRev=0x00,
173173
ProductId=0x45,
@@ -199,7 +199,7 @@ def test_uart_frame_received_error():
199199
uart = znp_uart.ZnpMtProtocol(api)
200200
uart.connection_made(transport)
201201

202-
test_command = c.Sys.ResetInd.Callback(
202+
test_command = c.SYS.ResetInd.Callback(
203203
Reason=t.ResetReason.PowerUp,
204204
TransportRev=0x00,
205205
ProductId=0x45,

zigpy_znp/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ async def connect(self) -> None:
161161

162162
try:
163163
# Make sure that our port works
164-
await self.request(c.Sys.Ping.Req())
164+
await self.request(c.SYS.Ping.Req())
165165
except Exception:
166166
self._uart = None
167167
raise
@@ -347,15 +347,15 @@ async def nvram_write(
347347
value = value.serialize()
348348

349349
return await self.request(
350-
c.Sys.OSALNVWrite.Req(Id=nv_id, Offset=offset, Value=t.ShortBytes(value)),
350+
c.SYS.OSALNVWrite.Req(Id=nv_id, Offset=offset, Value=t.ShortBytes(value)),
351351
RspStatus=t.Status.SUCCESS,
352352
)
353353

354354
async def nvram_read(
355355
self, nv_id: nvids.BaseNvIds, *, offset: t.uint8_t = 0
356356
) -> bytes:
357357
response = await self.request(
358-
c.Sys.OSALNVRead.Req(Id=nv_id, Offset=offset), RspStatus=t.Status.SUCCESS,
358+
c.SYS.OSALNVRead.Req(Id=nv_id, Offset=offset), RspStatus=t.Status.SUCCESS,
359359
)
360360

361361
return response.Value

zigpy_znp/commands/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from .app_config import AppConfig
55
from .mac import MAC
66
from .sapi import SAPI
7-
from .sys import Sys
7+
from .sys import SYS
88
from .util import Util
99
from .zdo import ZDO
1010
from .zgp import ZGP
@@ -16,7 +16,7 @@
1616
AppConfig,
1717
MAC,
1818
SAPI,
19-
Sys,
19+
SYS,
2020
Util,
2121
ZDO,
2222
ZGP,

0 commit comments

Comments
 (0)