Skip to content

Commit

Permalink
Implement command priority
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Dec 23, 2023
1 parent 1bb23d4 commit 61a9c99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = {text = "GPL-3.0"}
requires-python = ">=3.8"
dependencies = [
"voluptuous",
"zigpy>=0.60.0",
"zigpy>=0.60.2",
"pyusb>=1.1.0",
"gpiozero",
'async-timeout; python_version<"3.11"',
Expand Down
13 changes: 11 additions & 2 deletions zigpy_zigate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import logging
from typing import Any, Dict

from zigpy.datastructures import PriorityLock
import zigpy.exceptions

import zigpy_zigate.uart
Expand Down Expand Up @@ -217,7 +218,7 @@ def __init__(self, device_config: Dict[str, Any]):
self._uart = None
self._awaiting = {}
self._status_awaiting = {}
self._lock = asyncio.Lock()
self._lock = PriorityLock()

self.network_state = None

Expand Down Expand Up @@ -295,6 +296,14 @@ async def wait_for_response(self, wait_response):
self._awaiting[wait_response].cancel()
del self._awaiting[wait_response]

def _get_command_priority(self, cmd):
return {
# Watchdog command is prioritized
CommandId.SET_TIMESERVER: 9999,
# APS command is deprioritized
CommandId.SEND_RAW_APS_DATA_PACKET: -1,
}.get(cmd, 0)

async def command(
self,
cmd,
Expand All @@ -303,7 +312,7 @@ async def command(
wait_status=True,
timeout=COMMAND_TIMEOUT,
):
async with self._lock:
async with self._lock(priority=self._get_command_priority(cmd)):
tries = 3

tasks = []
Expand Down

0 comments on commit 61a9c99

Please sign in to comment.