Skip to content

Commit

Permalink
Merge branch 'main' into PLW2901
Browse files Browse the repository at this point in the history
# Conflicts:
#	pyproject.toml
  • Loading branch information
joostlek committed Feb 21, 2024
2 parents f2094ef + fc222c9 commit 345d875
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 27 deletions.
8 changes: 0 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,11 @@ ignore = [
"D203", # Conflicts with other rules
"D213", # Conflicts with other rules
"DTZ005",
"EM101",
"EM102",
"FBT002",
"FBT003",
"TRY002",
"TRY003",
"TRY300",
"TRY400",
"COM812", # Conflicts with other rules
"ISC001", # Conflicts with other rules
"PLR2004", # Just annoying, not really useful
"PLR0912",
"SIM102",
]
select = ["ALL"]

Expand Down
17 changes: 13 additions & 4 deletions roombapy/entry_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import sys

from roombapy import RoombaFactory
from roombapy import RoombaConnectionError, RoombaFactory
from roombapy.discovery import RoombaDiscovery
from roombapy.getpassword import RoombaPassword

Expand Down Expand Up @@ -61,19 +61,28 @@ def connect():
pass


class ValidationError(Exception):
"""Validation error."""

def __init__(self, *, field: str) -> None:
"""Initialize the exception."""
super().__init__(f"{field} cannot be null")


def _validate_ip(ip):
if ip is None:
raise Exception("ip cannot be null")
raise ValidationError(field="IP")


def _validate_password(ip):
if ip is None:
raise Exception("password cannot be null")
raise ValidationError(field="Password")


def _validate_roomba_info(roomba_info):
if roomba_info is None:
raise Exception("cannot find roomba")
msg = "cannot find roomba"
raise RoombaConnectionError(msg)


def _wait_for_input():
Expand Down
3 changes: 2 additions & 1 deletion roombapy/getpassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,14 @@ def _get_response(self):
if len(raw_data) >= 2:
response_length = struct.unpack("B", raw_data[1:2])[0]
self.server_socket.close()
return raw_data
except socket.timeout:
self.log.warning("Socket timeout")
return None
except OSError as e:
self.log.debug("Socket error: %s", e)
return None
else:
return raw_data


def _decode_password(data):
Expand Down
9 changes: 4 additions & 5 deletions roombapy/remote_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ def connect(self):
)
try:
self._open_mqtt_connection()
except Exception:
self.log.exception("Can't connect to %s", self.address)
else:
return True
except Exception as e: # noqa: BLE001
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)
Expand Down Expand Up @@ -121,7 +120,7 @@ def _get_mqtt_client(self):
self.log.debug("Setting TLS certificate")
ssl_context = generate_tls_context()
mqtt_client.tls_set_context(ssl_context)
mqtt_client.tls_insecure_set(True)
mqtt_client.tls_insecure_set(True) # noqa: FBT003

return mqtt_client

Expand Down
10 changes: 4 additions & 6 deletions roombapy/roomba.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ def connect(self):
def _connect(self):
is_connected = self.remote_client.connect()
if not is_connected:
raise RoombaConnectionError(
f"Unable to connect to Roomba at {self.remote_client.address}"
)
msg = f"Unable to connect to Roomba at {self.remote_client.address}"
raise RoombaConnectionError(msg)
return is_connected

def disconnect(self):
Expand Down Expand Up @@ -180,9 +179,8 @@ def on_disconnect(self, error):

def on_message(self, _mosq, _obj, msg):
"""On message callback."""
if self.exclude != "":
if self.exclude in msg.topic:
return
if self.exclude != "" and self.exclude in msg.topic:
return

if self.indent == 0:
self.master_indent = max(self.master_indent, len(msg.topic))
Expand Down
9 changes: 6 additions & 3 deletions roombapy/roomba_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ class RoombaInfo(BaseModel):
def hostname_validator(cls, value: str) -> str:
"""Validate the hostname."""
if "-" not in value:
raise ValueError(f"hostname does not contain a dash: {value}")
msg = f"hostname does not contain a dash: {value}"
raise ValueError(msg)
model_name, blid = value.split("-")
if blid == "":
raise ValueError(f"empty blid: {value}")
msg = f"empty blid: {value}"
raise ValueError(msg)
if model_name.lower() not in {"roomba", "irobot"}:
raise ValueError(f"unsupported model in hostname: {value}")
msg = f"unsupported model in hostname: {value}"
raise ValueError(msg)
return value

@cached_property
Expand Down

0 comments on commit 345d875

Please sign in to comment.