Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support zigpy packet priority #255

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
license = {text = "GPL-3.0"}
requires-python = ">=3.8"
dependencies = [
"zigpy>=0.60.2",
"zigpy>=0.69.0",
"async_timeout",
"voluptuous",
"coloredlogs",
Expand Down
29 changes: 18 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ def __repr__(self):
return f"<{type(self).__name__} to {self.protocol}>"


def config_for_port_path(path):
return conf.CONFIG_SCHEMA(
{
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
}
)
def config_for_port_path(path, apply_schema: bool = True):
config = {
conf.CONF_DEVICE: {conf.CONF_DEVICE_PATH: path},
zigpy.config.CONF_NWK_BACKUP_ENABLED: False,
}

if apply_schema:
return conf.CONFIG_SCHEMA(config)

return config


@pytest.fixture
Expand Down Expand Up @@ -272,10 +275,14 @@ def inner(
server_config=None,
**kwargs,
):
default = config_for_port_path(FAKE_SERIAL_PORT)

client_config = merge_dicts(default, client_config or {})
server_config = merge_dicts(default, server_config or {})
client_config = merge_dicts(
config_for_port_path(FAKE_SERIAL_PORT, apply_schema=False),
client_config or {},
)
server_config = merge_dicts(
config_for_port_path(FAKE_SERIAL_PORT),
server_config or {},
)

app = ControllerApplication(client_config)

Expand Down
3 changes: 3 additions & 0 deletions tests/tools/test_network_backup_restore.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import asyncio
import dataclasses

import pytest
Expand Down Expand Up @@ -293,6 +294,7 @@ async def test_nwk_frame_counter_zstack30(make_connected_znp):

await security.write_nwk_frame_counter(znp, 0xAABBCCDD)
assert (await security.read_nwk_frame_counter(znp)) == 0xAABBCCDD
await asyncio.sleep(0.1)


async def test_nwk_frame_counter_zstack33(make_connected_znp):
Expand Down Expand Up @@ -333,6 +335,7 @@ async def test_nwk_frame_counter_zstack33(make_connected_znp):

await security.write_nwk_frame_counter(znp, 0x98765432)
assert (await security.read_nwk_frame_counter(znp)) == 0x98765432
await asyncio.sleep(0.1)


def ieee_and_key(text) -> zigpy.state.Key:
Expand Down
2 changes: 1 addition & 1 deletion zigpy_znp/tools/energy_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
async def perform_energy_scan(radio_path, num_scans=None):
LOGGER.info("Starting up zigpy-znp")

config = ControllerApplication.SCHEMA({"device": {"path": radio_path}})
config = {"device": {"path": radio_path}}
app = ControllerApplication(config)
await app.connect()

Expand Down
2 changes: 1 addition & 1 deletion zigpy_znp/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None:
# Don't release the concurrency-limiting semaphore until we are done trying.
# There is no point in allowing requests to take turns getting buffer errors.
try:
async with self._limit_concurrency():
async with self._limit_concurrency(priority=packet.priority):
for attempt in range(REQUEST_MAX_RETRIES):
try:
# ZDO requests do not generate `AF.DataConfirm` messages
Expand Down
22 changes: 13 additions & 9 deletions zigpy_znp/zigbee/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging

import zigpy.zdo
import zigpy.types
import zigpy.device
import zigpy.application

Expand All @@ -22,7 +23,7 @@ def manufacturer(self):
def model(self):
return "Coordinator"

def request(
async def request(
self,
profile,
cluster,
Expand All @@ -31,22 +32,25 @@ def request(
sequence,
data,
expect_reply=True,
# Extend the default timeout
timeout=2 * zigpy.device.APS_REPLY_TIMEOUT,
use_ieee=False,
ask_for_ack: bool | None = None,
priority: int = zigpy.types.PacketPriority.NORMAL,
):
"""
Normal `zigpy.device.Device:request` except its default timeout is longer.
"""

return super().request(
profile,
cluster,
src_ep,
dst_ep,
sequence,
data,
return await super().request(
profile=profile,
cluster=cluster,
src_ep=src_ep,
dst_ep=dst_ep,
sequence=sequence,
data=data,
expect_reply=expect_reply,
timeout=timeout,
use_ieee=use_ieee,
ask_for_ack=ask_for_ack,
priority=priority,
)