Skip to content

Commit 61a9c99

Browse files
committed
Implement command priority
1 parent 1bb23d4 commit 61a9c99

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ license = {text = "GPL-3.0"}
1515
requires-python = ">=3.8"
1616
dependencies = [
1717
"voluptuous",
18-
"zigpy>=0.60.0",
18+
"zigpy>=0.60.2",
1919
"pyusb>=1.1.0",
2020
"gpiozero",
2121
'async-timeout; python_version<"3.11"',

zigpy_zigate/api.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import logging
77
from typing import Any, Dict
88

9+
from zigpy.datastructures import PriorityLock
910
import zigpy.exceptions
1011

1112
import zigpy_zigate.uart
@@ -217,7 +218,7 @@ def __init__(self, device_config: Dict[str, Any]):
217218
self._uart = None
218219
self._awaiting = {}
219220
self._status_awaiting = {}
220-
self._lock = asyncio.Lock()
221+
self._lock = PriorityLock()
221222

222223
self.network_state = None
223224

@@ -295,6 +296,14 @@ async def wait_for_response(self, wait_response):
295296
self._awaiting[wait_response].cancel()
296297
del self._awaiting[wait_response]
297298

299+
def _get_command_priority(self, cmd):
300+
return {
301+
# Watchdog command is prioritized
302+
CommandId.SET_TIMESERVER: 9999,
303+
# APS command is deprioritized
304+
CommandId.SEND_RAW_APS_DATA_PACKET: -1,
305+
}.get(cmd, 0)
306+
298307
async def command(
299308
self,
300309
cmd,
@@ -303,7 +312,7 @@ async def command(
303312
wait_status=True,
304313
timeout=COMMAND_TIMEOUT,
305314
):
306-
async with self._lock:
315+
async with self._lock(priority=self._get_command_priority(cmd)):
307316
tries = 3
308317

309318
tasks = []

0 commit comments

Comments
 (0)