Skip to content

Commit cb985f4

Browse files
authored
Merge pull request #202 from plugwise/bugfix/arnout/asyncio_fixes
Bugfix/arnout/asyncio_fixes
2 parents 596f47e + 8a3623d commit cb985f4

File tree

9 files changed

+37
-25
lines changed

9 files changed

+37
-25
lines changed

.github/workflows/merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Latest release
55

66
env:
77
CACHE_VERSION: 21
8-
DEFAULT_PYTHON: "3.12"
8+
DEFAULT_PYTHON: "3.13"
99

1010
# Only run on merges
1111
on:

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name: Latest commit
55

66
env:
77
CACHE_VERSION: 7
8-
DEFAULT_PYTHON: "3.12"
8+
DEFAULT_PYTHON: "3.13"
99
PRE_COMMIT_HOME: ~/.cache/pre-commit
1010

1111
on:

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ci:
77

88
default_language_version:
99
# force all unspecified python hooks to run python3
10-
python: python3.12
10+
python: python3.13
1111

1212
repos:
1313
# Run manually in CI skipping the branch checks
@@ -28,18 +28,18 @@ repos:
2828
args:
2929
- --branch=main
3030
- repo: https://github.com/asottile/pyupgrade
31-
rev: v3.19.0
31+
rev: v3.19.1
3232
hooks:
3333
- id: pyupgrade
3434
args: [--py39-plus]
3535
# Moved codespell configuration to setup.cfg as per 'all-files' issues not reading args
3636
- repo: https://github.com/codespell-project/codespell
37-
rev: v2.3.0
37+
rev: v2.4.1
3838
hooks:
3939
- id: codespell
4040
exclude_types: [csv, json]
4141
- repo: https://github.com/PyCQA/bandit
42-
rev: 1.8.0
42+
rev: 1.8.2
4343
hooks:
4444
- id: bandit
4545
args:
@@ -52,7 +52,7 @@ repos:
5252
hooks:
5353
- id: yamllint
5454
- repo: https://github.com/biomejs/pre-commit
55-
rev: v0.5.0
55+
rev: v0.6.1
5656
hooks:
5757
- id: biome-lint
5858
additional_dependencies: ["@biomejs/[email protected]"]
@@ -102,6 +102,6 @@ repos:
102102
language: script
103103
pass_filenames: false
104104
- repo: https://github.com/igorshubovych/markdownlint-cli
105-
rev: v0.43.0
105+
rev: v0.44.0
106106
hooks:
107107
- id: markdownlint

plugwise_usb/connection/queue.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ async def _send_queue_worker(self) -> None:
137137
self._submit_queue.task_done()
138138
return
139139

140-
while self._stick.queue_depth > 3:
141-
_LOGGER.info("Awaiting plugwise responses %d", self._stick.queue_depth)
140+
if self._stick.queue_depth > 3:
142141
await sleep(0.125)
142+
if self._stick.queue_depth > 3:
143+
_LOGGER.warning("Awaiting plugwise responses %d", self._stick.queue_depth)
143144

144145
await self._stick.write_to_stick(request)
145146
self._submit_queue.task_done()

plugwise_usb/connection/receiver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,9 @@ def connection_made(self, transport: SerialTransport) -> None:
166166

167167
async def close(self) -> None:
168168
"""Close connection."""
169-
if self._transport is None:
170-
return
171-
self._transport.close()
172169
await self._stop_running_tasks()
170+
if self._transport:
171+
self._transport.close()
173172

174173
async def _stop_running_tasks(self) -> None:
175174
"""Cancel and stop any running task."""
@@ -183,10 +182,12 @@ async def _stop_running_tasks(self) -> None:
183182
cancel_response.priority = Priority.CANCEL
184183
await self._message_queue.put(cancel_response)
185184
await self._message_worker_task
186-
self._message_worker_task = None
185+
self._message_worker_task = None
186+
187187
if self._data_worker_task is not None and not self._data_worker_task.done():
188188
await self._data_queue.put(b"FFFFFFFF")
189189
await self._data_worker_task
190+
self._data_worker_task = None
190191

191192
# region Process incoming data
192193

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "plugwise_usb"
7-
version = "v0.40.0a27"
7+
version = "v0.40.0a29"
88
license = {file = "LICENSE"}
99
description = "Plugwise USB (Stick) module for Python 3."
1010
readme = "README.md"
@@ -219,7 +219,7 @@ omit= [
219219
]
220220

221221
[tool.ruff]
222-
target-version = "py312"
222+
target-version = "py313"
223223

224224
lint.select = [
225225
"B002", # Python does not support the unary prefix increment
@@ -306,6 +306,7 @@ lint.ignore = [
306306
"PLW2901", # Outer {outer_kind} variable {name} overwritten by inner {inner_kind} target
307307
"UP006", # keep type annotation style as is
308308
"UP007", # keep type annotation style as is
309+
"UP031"
309310
# Ignored due to performance: https://github.com/charliermarsh/ruff/issues/2923
310311
#"UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)`
311312
]

scripts/python-venv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eu
33

4-
pyversions=(3.12 3.11)
4+
pyversions=( 3.13 )
55
my_path=$(git rev-parse --show-toplevel)
66
my_venv=${my_path}/venv
77

tests/bandit.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ tests:
1212
- B317
1313
- B318
1414
- B319
15-
- B320
1615
- B601
1716
- B602
1817
- B604

tests/test_usb.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class DummyTransport:
7777
def __init__(
7878
self,
7979
loop: asyncio.AbstractEventLoop,
80-
test_data: dict[bytes, tuple[str, bytes, bytes]] | None = None,
80+
test_data: dict[bytes, tuple[str, bytes, bytes | None]] | None = None,
8181
) -> None:
8282
"""Initialize dummy transport class."""
8383
self._loop = loop
@@ -169,7 +169,7 @@ class MockSerial:
169169
"""Mock serial connection."""
170170

171171
def __init__(
172-
self, custom_response: dict[bytes, tuple[str, bytes, bytes]] | None
172+
self, custom_response: dict[bytes, tuple[str, bytes, bytes | None]] | None
173173
) -> None:
174174
"""Init mocked serial connection."""
175175
self.custom_response = custom_response
@@ -421,7 +421,7 @@ async def test_stick_connect_timeout(self, monkeypatch: pytest.MonkeyPatch) -> N
421421
b"\x05\x05\x03\x03000AB43C\r\n": (
422422
"STICK INIT timeout",
423423
b"000000E1", # Timeout ack
424-
b"",
424+
None,
425425
),
426426
}
427427
).mock_connection,
@@ -526,6 +526,7 @@ async def node_loaded(self, event: pw_api.NodeEvent, mac: str) -> None: # type:
526526
f"Invalid {event} event, expected " + f"{pw_api.NodeEvent.LOADED}"
527527
)
528528
)
529+
529530
async def node_motion_state(
530531
self,
531532
feature: pw_api.NodeFeature, # type: ignore[name-defined]
@@ -1497,7 +1498,7 @@ async def test_stick_network_down(self, monkeypatch: pytest.MonkeyPatch) -> None
14971498
def fake_env(self, env: str) -> str | None:
14981499
"""Fake environment."""
14991500
if env == "APPDATA":
1500-
return "c:\\user\\tst\\appdata"
1501+
return "appdata_folder"
15011502
if env == "~":
15021503
return "/home/usr"
15031504
return None
@@ -2125,7 +2126,6 @@ def fake_cache(dummy: object, setting: str) -> str | None:
21252126
construct_message(b"0100555555555555555500BF", b"0000")
21262127
)
21272128

2128-
21292129
async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ignore[name-defined]
21302130
"""Load callback for event."""
21312131

@@ -2418,12 +2418,22 @@ async def test_node_discovery_and_load(
24182418
# Get state
24192419
get_state_timestamp = dt.now(UTC).replace(minute=0, second=0, microsecond=0)
24202420
state = await stick.nodes["0098765432101234"].get_state(
2421-
(pw_api.NodeFeature.AVAILABLE, pw_api.NodeFeature.PING, pw_api.NodeFeature.INFO, pw_api.NodeFeature.RELAY)
2421+
(
2422+
pw_api.NodeFeature.AVAILABLE,
2423+
pw_api.NodeFeature.PING,
2424+
pw_api.NodeFeature.INFO,
2425+
pw_api.NodeFeature.RELAY,
2426+
)
24222427
)
24232428

24242429
# Check Available
24252430
assert state[pw_api.NodeFeature.AVAILABLE].state
2426-
assert state[pw_api.NodeFeature.AVAILABLE].last_seen.replace(minute=0, second=0, microsecond=0) == get_state_timestamp
2431+
assert (
2432+
state[pw_api.NodeFeature.AVAILABLE].last_seen.replace(
2433+
minute=0, second=0, microsecond=0
2434+
)
2435+
== get_state_timestamp
2436+
)
24272437

24282438
# Check Ping
24292439
assert state[pw_api.NodeFeature.PING].rssi_in == 69

0 commit comments

Comments
 (0)