Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
LaStrada committed Jan 1, 2025
1 parent a3b6a85 commit cdf3f2d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion airthings_ble/device_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def _wave_enhance_need_firmware_upgrade(self, version: str) -> bool:
return False

semantic_version = re.compile(r"(\d+)\.(\d+)\.(\d+)")
major, minor, patch = semantic_version.match(match[0]).groups()
match_obj = semantic_version.match(match[0])
if not match_obj:
_LOGGER.warning("Invalid semantic version string: %s", match[0])
return False
major, minor, patch = match_obj.groups()

return not (int(major) >= 2 and int(minor) >= 6 and int(patch) >= 1)
10 changes: 5 additions & 5 deletions airthings_ble/wave_enhance/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
raise ValueError("Response cannot be None")
self.response = response
self.random_bytes = random_bytes
self.path = path.as_bytes()
self.path = path

def parse(self) -> dict[str, float | str | None] | None:
if self.response[0:5] != self._header:
Expand Down Expand Up @@ -106,18 +106,18 @@ def parse(self) -> dict[str, float | str | None] | None:
raise ValueError("Invalid response element")

path_length = self.response[10] - 0x60
if path_length != len(self.path):
if path_length != len(self.path.as_bytes()):
self.logger.debug(
"Invalid path length, expected %d, but got %d",
len(self.path),
len(self.path.as_bytes()),
path_length,
)
raise ValueError("Invalid response path length")

if self.response[11 : 11 + path_length] != self.path:
if self.response[11 : 11 + path_length] != self.path.as_bytes():
self.logger.debug(
"Invalid response path, expected %s, but got %s",
self.path,
self.path.as_bytes(),
self.response[11 : 11 + path_length],
)
raise ValueError("Invalid response path")
Expand Down

0 comments on commit cdf3f2d

Please sign in to comment.