From 24c8eadcbe292f756faea2c3a8c3e8beb5bbc5e4 Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Fri, 27 Sep 2024 21:58:17 +0100 Subject: [PATCH] Make non-top-level connection errors `debug` level This avoids spamming the home-assistant logs, which can occur when home-assistant has been running but the roomba hasn't been turned on, so no initial connection has been established. This allows users to read the logs/investigate other home-assistant issues, without having to disable the roomba integration. For example instead of this message being repeated 3x: ``` 2024-MM-DD HH:MM:SS.MMM ERROR (roombapy) [roombapy.remote_client] Can't connect to 192.168.0.123 Traceback (most recent call last): File .../lib/python3.12/site-packages/roombapy/remote_client.py", line 93, in connect self._open_mqtt_connection() File .../lib/python3.12/site-packages/roombapy/remote_client.py", line 117, in _open_mqtt_connection self.mqtt_client.connect(self.address, self.port) File .../lib/python3.12/site-packages/paho/mqtt/client.py", line 914, in connect return self.reconnect() ^^^^^^^^^^^^^^^^ File .../lib/python3.12/site-packages/paho/mqtt/client.py", line 1044, in reconnect sock = self._create_socket_connection() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File .../lib/python3.12/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File .../lib/python3.12/socket.py", line 865, in create_connection raise exceptions[0] File .../lib/python3.12/socket.py", line 850, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host ``` and these then following: ``` 2024-MM-DD HH:MM:SS.MMM ERROR (roombapy) [roombapy.remote_client] Unable to connect to 192.168.0.123 2024-MM-DD HH:MM:SS.MMM WARNING (roombapy) [roombapy.roomba] Unexpectedly disconnected from Roomba 192.168.0.123, code The connection was lost 2024-MM-DD HH:MM:SS.MMM WARNING (roombapy) [roombapy.roomba] Periodic connection lost due to Unable to connect to Roomba at 192.168.0.123 ``` we now receive: ``` 2024-MM-DD HH:MM:SS.MMM WARNING (roombapy) [roombapy.roomba] Unexpectedly disconnected from Roomba 192.168.0.123, code The connection was lost ``` With the ability to get back more detailed connection logs by enabling debug logging in home-assistant. --- roombapy/remote_client.py | 4 ++-- roombapy/roomba.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/roombapy/remote_client.py b/roombapy/remote_client.py index e2cf078..0aacfc0 100644 --- a/roombapy/remote_client.py +++ b/roombapy/remote_client.py @@ -92,12 +92,12 @@ def connect(self) -> bool: try: self._open_mqtt_connection() except Exception: - self.log.exception("Can't connect to %s", self.address) + self.log.debug("Can't connect to %s", self.address) else: return True attempt += 1 - self.log.error("Unable to connect to %s", self.address) + self.log.debug("Unable to connect to %s", self.address) return False def disconnect(self) -> None: diff --git a/roombapy/roomba.py b/roombapy/roomba.py index 4a18edf..3b94002 100644 --- a/roombapy/roomba.py +++ b/roombapy/roomba.py @@ -167,7 +167,7 @@ def periodic_connection(self) -> None: except RoombaConnectionError as error: self.periodic_connection_running = False self.on_disconnect(MQTT_ERROR_MESSAGES[7]) - self.log.warning("Periodic connection lost due to %s", error) + self.log.debug("Periodic connection lost due to %s", error) return time.sleep(self.delay)