Skip to content

Commit

Permalink
Make non-top-level connection errors debug level
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bobrippling committed Oct 23, 2024
1 parent c254c70 commit c0597a8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions roombapy/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def connect(self) -> bool:
try:
self._open_mqtt_connection()
except Exception:

Check failure on line 94 in roombapy/remote_client.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (BLE001)

roombapy/remote_client.py:94:20: BLE001 Do not catch blind exception: `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:
Expand Down
2 changes: 1 addition & 1 deletion roombapy/roomba.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,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)

Expand Down

0 comments on commit c0597a8

Please sign in to comment.