Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make roomaby usable for smarthomeNG #217

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions roombapy/remote_client.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import logging
import ssl
from functools import cache
from functools import lru_cache

import paho.mqtt.client as mqtt

from roombapy.const import MQTT_ERROR_MESSAGES
from .const import MQTT_ERROR_MESSAGES

MAX_CONNECTION_RETRIES = 3


@cache
@lru_cache(maxsize=None)
def _generate_tls_context() -> ssl.SSLContext:
"""Generate TLS context.

Expand Down Expand Up @@ -71,12 +71,15 @@ def connect(self):
self._open_mqtt_connection()
return True
except Exception as e:
_last_error = "Can't connect to {}, error: {}".format(self.address, e)
self.log.error(
"Can't connect to %s, error: %s", self.address, e
)
attempt += 1

self.log.error("Unable to connect to %s", self.address)
self.log.error("Client - Unable to connect to %s", self.address)
if self.on_connect is not None:
self.on_connect(_last_error)
return False

def disconnect(self):
Expand Down
1 change: 1 addition & 0 deletions roombapy/roomba.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def connect(self):
self.time = time.time() # save connection time

def _connect(self):
self.client_error=None
is_connected = self.remote_client.connect()
if not is_connected:
raise RoombaConnectionError(
Expand Down
Loading