Skip to content

Commit 5291d12

Browse files
committed
Improve logging
1 parent 4aeef0b commit 5291d12

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

plugwise_usb/connection/receiver.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ async def _receive_queue_worker(self):
222222
_LOGGER.debug("Receive_queue_worker started")
223223
while self.is_connected:
224224
response: PlugwiseResponse | None = await self._receive_queue.get()
225-
_LOGGER.debug("Process from queue: %s", response)
225+
_LOGGER.debug("Process from receive queue: %s", response)
226226
if isinstance(response, StickResponse):
227227
_LOGGER.debug("Received %s", response)
228228
await self._notify_stick_response_subscribers(response)
@@ -232,7 +232,7 @@ async def _receive_queue_worker(self):
232232
else:
233233
await self._notify_node_response_subscribers(response)
234234
self._receive_queue.task_done()
235-
_LOGGER.debug("Receive_queue_worker finished")
235+
_LOGGER.debug("Receive_queue_worker stopped")
236236

237237
def _reset_buffer(self, new_buffer: bytes) -> None:
238238
if new_buffer[:2] == MESSAGE_FOOTER:
@@ -342,7 +342,7 @@ async def _notify_node_response_subscribers(self, node_response: PlugwiseRespons
342342
notify_tasks.append(callback(node_response))
343343

344344
if len(notify_tasks) > 0:
345-
_LOGGER.debug("Notify node response subscribers (%s) about %s", len(notify_tasks), node_response)
345+
_LOGGER.info("Received %s", node_response)
346346
if node_response.seq_id not in BROADCAST_IDS:
347347
self._last_processed_messages.append(node_response.seq_id)
348348
if node_response.seq_id in self._delayed_processing_tasks:
@@ -351,6 +351,7 @@ async def _notify_node_response_subscribers(self, node_response: PlugwiseRespons
351351
self._last_processed_messages = self._last_processed_messages[-CACHED_REQUESTS:]
352352

353353
# execute callbacks
354+
_LOGGER.debug("Notify node response subscribers (%s) about %s", len(notify_tasks), node_response)
354355
task_result = await gather(*notify_tasks)
355356

356357
# Log execution result for special cases

plugwise_usb/connection/sender.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
5656
raise StickError("USB-Stick transport missing.")
5757

5858
await self._stick_lock.acquire()
59-
_LOGGER.debug("Send %s", request)
6059
self._current_request = request
6160
self._stick_response: Future[bytes] = self._loop.create_future()
6261

6362
request.add_send_attempt()
63+
_LOGGER.debug("Send %s", request)
6464
request.subscribe_to_responses(
6565
self._receiver.subscribe_to_stick_responses,
6666
self._receiver.subscribe_to_node_responses,
@@ -91,7 +91,7 @@ async def write_request_to_port(self, request: PlugwiseRequest) -> None:
9191
else:
9292
if response.response_type == StickResponseType.ACCEPT:
9393
request.seq_id = response.seq_id
94-
_LOGGER.info("Sent %s", request)
94+
_LOGGER.debug("USB-Stick accepted %s with seq_id=%s", request, response.seq_id)
9595
elif response.response_type == StickResponseType.TIMEOUT:
9696
_LOGGER.warning("USB-Stick responded with communication timeout for %s", request)
9797
request.assign_error(

plugwise_usb/messages/requests.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def __init__(
6666
def __repr__(self) -> str:
6767
"""Convert request into writable str."""
6868
if self._seq_id is None:
69-
return f"{self.__class__.__name__} (mac={self.mac_decoded}, seq_id=UNKNOWN, attempts={self._send_counter})"
70-
return f"{self.__class__.__name__} (mac={self.mac_decoded}, seq_id={self._seq_id}, attempts={self._send_counter})"
69+
return f"{self.__class__.__name__} (mac={self.mac_decoded}, seq_id=UNKNOWN, attempt={self._send_counter})"
70+
return f"{self.__class__.__name__} (mac={self.mac_decoded}, seq_id={self._seq_id}, attempt={self._send_counter})"
7171

7272
def response_future(self) -> Future[PlugwiseResponse]:
7373
"""Return awaitable future with response message."""
@@ -145,18 +145,20 @@ def _response_timeout_expired(self, stick_timeout: bool = False) -> None:
145145
"""Handle response timeout."""
146146
if self._response_future.done():
147147
return
148+
if stick_timeout:
149+
_LOGGER.info("USB-stick responded with time out to %s", self)
150+
else:
151+
_LOGGER.warning("No response received for %s within timeout (%s seconds)", self, NODE_TIME_OUT)
148152
self._seq_id = None
149153
self._unsubscribe_from_stick()
150154
self._unsubscribe_from_node()
151155
if stick_timeout:
152-
_LOGGER.warning("USB-stick responded with time out to %s", self)
153156
self._response_future.set_exception(
154157
StickTimeout(
155158
f"USB-stick responded with time out to {self}"
156159
)
157160
)
158161
else:
159-
_LOGGER.warning("No response received for %s within timeout (%s seconds)", self, NODE_TIME_OUT)
160162
self._response_future.set_exception(
161163
NodeTimeout(
162164
f"No device response to {self} within {NODE_TIME_OUT} seconds"

0 commit comments

Comments
 (0)