Skip to content

Commit 77b0375

Browse files
authored
Merge pull request #319 from plugwise/no-open-req
Replace useless warning message, various small corrections/improvements
2 parents c9f5948 + 9319c81 commit 77b0375

File tree

7 files changed

+42
-37
lines changed

7 files changed

+42
-37
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Ongoing
4+
5+
- PR [319](https://github.com/plugwise/python-plugwise-usb/pull/319): Replace unclear warning message when a node is not online, also various small improvements suggested by CRAI.
6+
37
## v0.44.11 - 2025-08-14
48

59
- Improve reading from energy-logs cache via PR [314](https://github.com/plugwise/python-plugwise-usb/pull/314)

plugwise_usb/connection/queue.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,14 @@ async def submit(self, request: PlugwiseRequest) -> PlugwiseResponse | None:
8585
f"Cannot send message {request} which is currently waiting for response."
8686
)
8787

88-
while request.resend:
88+
while True:
89+
if not request.resend:
90+
break
8991
_LOGGER.debug("submit | start (%s) %s", request.retries_left, request)
9092
if not self._running or self._stick is None:
9193
raise StickError(
92-
f"Cannot send message {request.__class__.__name__} for"
93-
+ f"{request.mac_decoded} because queue manager is stopped"
94+
f"Cannot send message {request.__class__.__name__} for "
95+
f"{request.mac_decoded} because queue manager is stopped"
9496
)
9597

9698
await self._add_request_to_queue(request)
@@ -107,20 +109,22 @@ async def submit(self, request: PlugwiseRequest) -> PlugwiseResponse | None:
107109
"%s, cancel because timeout is expected for NodePingRequests",
108110
exc,
109111
)
110-
elif request.resend:
112+
continue
113+
if request.resend:
111114
_LOGGER.debug("%s, retrying", exc)
112-
else:
113-
_LOGGER.warning("%s, cancel request", exc) # type: ignore[unreachable]
115+
continue
116+
_LOGGER.debug("%s, cancel request", exc)
117+
break
114118
except StickError as exc:
115119
_LOGGER.error(exc)
116120
raise StickError(
117121
f"No response received for {request.__class__.__name__} "
118-
+ f"to {request.mac_decoded}"
122+
f"to {request.mac_decoded}"
119123
) from exc
120124
except BaseException as exc:
121125
raise StickError(
122126
f"No response received for {request.__class__.__name__} "
123-
+ f"to {request.mac_decoded}"
127+
f"to {request.mac_decoded}"
124128
) from exc
125129

126130
return None

plugwise_usb/connection/sender.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
147147
async def _process_stick_response(self, response: StickResponse) -> None:
148148
"""Process stick response."""
149149
if self._stick_response is None or self._stick_response.done():
150-
_LOGGER.warning("No open request for %s", str(response))
151150
return
152151
_LOGGER.debug("Received %s as reply to %s", response, self._current_request)
153152
self._stick_response.set_result(response)

plugwise_usb/messages/requests.py

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""All known request messages to be send to plugwise devices."""
1+
"""All known request messages to be sent to plugwise devices."""
22

33
from __future__ import annotations
44

@@ -58,7 +58,7 @@
5858

5959

6060
class PlugwiseRequest(PlugwiseMessage):
61-
"""Base class for request messages to be send from by USB-Stick."""
61+
"""Base class for request messages to be sent from by USB-Stick."""
6262

6363
_reply_identifier: bytes = b"0000"
6464

@@ -215,7 +215,7 @@ def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
215215
if self._response_future.done():
216216
return
217217
if stick_timeout:
218-
_LOGGER.info("USB-stick responded with time out to %s", self)
218+
_LOGGER.info("USB-stick response timeout for %s", self)
219219
else:
220220
_LOGGER.info(
221221
"No response received for %s within %s seconds", self, NODE_TIME_OUT
@@ -225,12 +225,12 @@ def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
225225
self._unsubscribe_from_node()
226226
if stick_timeout:
227227
self._response_future.set_exception(
228-
StickTimeout(f"USB-stick responded with time out to {self}")
228+
StickTimeout(f"USB-stick response timeout for {self}")
229229
)
230230
else:
231231
self._response_future.set_exception(
232232
NodeTimeout(
233-
f"No device response to {self} within {NODE_TIME_OUT} seconds"
233+
f"No device response for {self} within {NODE_TIME_OUT} seconds"
234234
)
235235
)
236236

@@ -249,16 +249,17 @@ async def process_node_response(self, response: PlugwiseResponse) -> bool:
249249
if self._seq_id is None:
250250
_LOGGER.warning(
251251
"Received %s as reply to %s without a seq_id assigned",
252-
self._response,
252+
response,
253253
self,
254254
)
255255
return False
256256
if self._seq_id != response.seq_id:
257257
_LOGGER.warning(
258-
"Received %s as reply to %s which is not correct (expected seq_id=%s)",
259-
self._response,
258+
"Received %s as reply to %s with mismatched seq_id (expected=%r, got=%r)",
259+
response,
260260
self,
261-
str(self.seq_id),
261+
self.seq_id,
262+
response.seq_id,
262263
)
263264
return False
264265
if self._response_future.done():
@@ -297,19 +298,9 @@ async def _process_stick_response(self, stick_response: StickResponse) -> None:
297298
return
298299

299300
if stick_response.ack_id == StickResponseType.FAILED:
300-
self._unsubscribe_from_node()
301+
prev_seq_id = self._seq_id
301302
self._seq_id = None
302-
self._response_future.set_exception(
303-
NodeError(f"Stick failed request {self._seq_id}")
304-
)
305-
return
306-
307-
_LOGGER.debug(
308-
"Unknown StickResponseType %s at %s for request %s",
309-
str(stick_response.ack_id),
310-
stick_response,
311-
self,
312-
)
303+
self.assign_error(NodeError(f"Stick failed request {prev_seq_id!r}"))
313304

314305
async def _send_request(
315306
self, suppress_node_errors=False

plugwise_usb/network/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,12 @@ def _unsubscribe_to_protocol_events(self) -> None:
297297
if self._unsubscribe_node_awake is not None:
298298
self._unsubscribe_node_awake()
299299
self._unsubscribe_node_awake = None
300+
if self._unsubscribe_node_join is not None:
301+
self._unsubscribe_node_join()
302+
self._unsubscribe_node_join = None
303+
if self._unsubscribe_node_rejoin is not None:
304+
self._unsubscribe_node_rejoin()
305+
self._unsubscribe_node_rejoin = None
300306
if self._unsubscribe_stick_event is not None:
301307
self._unsubscribe_stick_event()
302308
self._unsubscribe_stick_event = None
@@ -322,10 +328,9 @@ async def discover_network_coordinator(self, load: bool = False) -> bool:
322328
ping_response = await ping_request.send()
323329
except StickTimeout as err:
324330
raise StickError(
325-
"The zigbee network coordinator (Circle+/Stealth+) with mac "
326-
+ "'%s' did not respond to ping request. Make "
327-
+ "sure the Circle+/Stealth+ is within reach of the USB-stick !",
328-
self._controller.mac_coordinator,
331+
f"The zigbee network coordinator (Circle+/Stealth+) with mac "
332+
f"'{self._controller.mac_coordinator}' did not respond to the ping request. "
333+
"Make sure the Circle+/Stealth+ is within reach of the USB-stick!"
329334
) from err
330335
if ping_response is None:
331336
return False
@@ -418,7 +423,9 @@ async def _discover_node(
418423
_LOGGER.debug("Starting the discovery of node %s with unknown NodeType", mac)
419424
node_info, node_ping = await self._controller.get_node_details(mac, ping_first)
420425
if node_info is None:
421-
_LOGGER.debug("Node %s with unknown NodeType not responding", mac)
426+
_LOGGER.warning(
427+
"Node %s with unknown NodeType not responding, is it offline?", mac
428+
)
422429
self._registry_stragglers.append(mac)
423430
return False
424431
await self._create_node_object(mac, node_info.node_type)

plugwise_usb/nodes/circle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ async def _load_from_cache(self) -> bool:
973973

974974
# Energy collection
975975
if not await self._energy_log_records_load_from_cache():
976-
_LOGGER.warning(
976+
_LOGGER.debug(
977977
"Node %s failed to load energy_log_records from cache",
978978
self._mac_in_str,
979979
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
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 = "0.44.11"
7+
version = "0.44.12a1"
88
license = "MIT"
99
keywords = ["home", "automation", "plugwise", "module", "usb"]
1010
classifiers = [

0 commit comments

Comments
 (0)