pschmitt / roombapy

Python program and library to control Wi-Fi enabled iRobot Roombas
MIT License
32 stars 23 forks source link

Make non-top-level connection errors `debug` level #361

Open bobrippling opened 2 months ago

bobrippling commented 2 months ago

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.

bobrippling commented 1 month ago

Rebased

bobrippling commented 1 week ago

The build error is on unchanged code - looks like it's been picked up by looking at context around the changes