Skip to content

Commit 06e3054

Browse files
authored
Support zigpy packet priority (#255)
* Use new zigpy packet priority API * Fix unit tests * Remove unnecessary schema conversions in tools * Try to delay a little when reading frame counters
1 parent 0035116 commit 06e3054

File tree

6 files changed

+37
-23
lines changed

6 files changed

+37
-23
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
license = {text = "GPL-3.0"}
1515
requires-python = ">=3.8"
1616
dependencies = [
17-
"zigpy>=0.60.2",
17+
"zigpy>=0.69.0",
1818
"async_timeout",
1919
"voluptuous",
2020
"coloredlogs",

tests/conftest.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,16 @@ def __repr__(self):
129129
return f"<{type(self).__name__} to {self.protocol}>"
130130

131131

132-
def config_for_port_path(path):
133-
return conf.CONFIG_SCHEMA(
134-
{
135-
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
136-
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
137-
}
138-
)
132+
def config_for_port_path(path, apply_schema: bool = True):
133+
config = {
134+
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
135+
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
136+
}
137+
138+
if apply_schema:
139+
return conf.CONFIG_SCHEMA(config)
140+
141+
return config
139142

140143

141144
@pytest.fixture
@@ -272,10 +275,14 @@ def inner(
272275
server_config=None,
273276
**kwargs,
274277
):
275-
default = config_for_port_path(FAKE_SERIAL_PORT)
276-
277-
client_config = merge_dicts(default, client_config or {})
278-
server_config = merge_dicts(default, server_config or {})
278+
client_config = merge_dicts(
279+
config_for_port_path(FAKE_SERIAL_PORT, apply_schema=False),
280+
client_config or {},
281+
)
282+
server_config = merge_dicts(
283+
config_for_port_path(FAKE_SERIAL_PORT),
284+
server_config or {},
285+
)
279286

280287
app = ControllerApplication(client_config)
281288

tests/tools/test_network_backup_restore.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import asyncio
23
import dataclasses
34

45
import pytest
@@ -293,6 +294,7 @@ async def test_nwk_frame_counter_zstack30(make_connected_znp):
293294

294295
await security.write_nwk_frame_counter(znp, 0xAABBCCDD)
295296
assert (await security.read_nwk_frame_counter(znp)) == 0xAABBCCDD
297+
await asyncio.sleep(0.1)
296298

297299

298300
async def test_nwk_frame_counter_zstack33(make_connected_znp):
@@ -333,6 +335,7 @@ async def test_nwk_frame_counter_zstack33(make_connected_znp):
333335

334336
await security.write_nwk_frame_counter(znp, 0x98765432)
335337
assert (await security.read_nwk_frame_counter(znp)) == 0x98765432
338+
await asyncio.sleep(0.1)
336339

337340

338341
def ieee_and_key(text) -> zigpy.state.Key:

zigpy_znp/tools/energy_scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
async def perform_energy_scan(radio_path, num_scans=None):
1818
LOGGER.info("Starting up zigpy-znp")
1919

20-
config = ControllerApplication.SCHEMA({"device": {"path": radio_path}})
20+
config = {"device": {"path": radio_path}}
2121
app = ControllerApplication(config)
2222
await app.connect()
2323

zigpy_znp/zigbee/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None:
931931
# Don't release the concurrency-limiting semaphore until we are done trying.
932932
# There is no point in allowing requests to take turns getting buffer errors.
933933
try:
934-
async with self._limit_concurrency():
934+
async with self._limit_concurrency(priority=packet.priority):
935935
for attempt in range(REQUEST_MAX_RETRIES):
936936
try:
937937
# ZDO requests do not generate `AF.DataConfirm` messages

zigpy_znp/zigbee/device.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44

55
import zigpy.zdo
6+
import zigpy.types
67
import zigpy.device
78
import zigpy.application
89

@@ -22,7 +23,7 @@ def manufacturer(self):
2223
def model(self):
2324
return "Coordinator"
2425

25-
def request(
26+
async def request(
2627
self,
2728
profile,
2829
cluster,
@@ -31,22 +32,25 @@ def request(
3132
sequence,
3233
data,
3334
expect_reply=True,
34-
# Extend the default timeout
3535
timeout=2 * zigpy.device.APS_REPLY_TIMEOUT,
3636
use_ieee=False,
37+
ask_for_ack: bool | None = None,
38+
priority: int = zigpy.types.PacketPriority.NORMAL,
3739
):
3840
"""
3941
Normal `zigpy.device.Device:request` except its default timeout is longer.
4042
"""
4143

42-
return super().request(
43-
profile,
44-
cluster,
45-
src_ep,
46-
dst_ep,
47-
sequence,
48-
data,
44+
return await super().request(
45+
profile=profile,
46+
cluster=cluster,
47+
src_ep=src_ep,
48+
dst_ep=dst_ep,
49+
sequence=sequence,
50+
data=data,
4951
expect_reply=expect_reply,
5052
timeout=timeout,
5153
use_ieee=use_ieee,
54+
ask_for_ack=ask_for_ack,
55+
priority=priority,
5256
)

0 commit comments

Comments
 (0)