Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ repos:
args:
- --fix
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
rev: v1.19.1
hooks:
- id: mypy
exclude: cli.py
additional_dependencies: [ "types-paho-mqtt", "types-protobuf" ]
exclude: ^roborock/cli\.py$
additional_dependencies: [ "types-PyYAML", "types-paho-mqtt", "types-protobuf" ]
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.23.0
hooks:
Expand Down
8 changes: 0 additions & 8 deletions mypy.ini

This file was deleted.

12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ dev = [
"pytest",
"pre-commit>=3.5,<5.0",
"mypy",
"types-PyYAML",
"types-paho-mqtt",
"types-protobuf",
"ruff==0.14.11",
"codespell",
"aioresponses>=0.7.7,<0.8",
Expand Down Expand Up @@ -143,8 +146,15 @@ extend-exclude = ["roborock/map/proto/*_pb2.py"]
"roborock/map/proto/*_pb2.py" = ["E501", "I001", "UP009"]
"tests/*" = ["B010"]

[tool.mypy]
check_untyped_defs = true

[[tool.mypy.overrides]]
module = ["construct"]
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = ["roborock.map.proto.*"]
module = ["roborock.cli", "roborock.map.proto.*"]
ignore_errors = true

[tool.pytest.ini_options]
Expand Down
2 changes: 1 addition & 1 deletion roborock/data/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def from_dict(cls, data: dict[str, Any]):
return cls(**result)

@staticmethod
def convert_dict(types_map: dict[Any, type], data: dict[Any, Any]) -> dict[Any, Any]:
def convert_dict(types_map: dict[Any, Any], data: dict[Any, Any]) -> dict[Any, Any]:
"""Generic helper to convert a dictionary of values based on a schema map of types.

This is meant to be used by traits that use dataclass reflection similar to
Expand Down
4 changes: 2 additions & 2 deletions roborock/devices/traits/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ class DpsDataConverter(Generic[TDps]):
to optimize repeated updates from device streams.
"""

def __init__(self, dps_type_map: dict[TDps, type], dps_field_map: dict[TDps, str]):
def __init__(self, dps_type_map: dict[TDps, Any], dps_field_map: dict[TDps, str]):
"""Initialize the converter for a specific RoborockBase-derived class."""
self._dps_type_map = dps_type_map
self._dps_field_map = dps_field_map

@classmethod
def from_dataclass(cls, dataclass_type: type[RoborockBase]):
"""Initialize the converter for a specific RoborockBase-derived class."""
dps_type_map: dict[TDps, type] = {}
dps_type_map: dict[TDps, Any] = {}
dps_field_map: dict[TDps, str] = {}
for field_obj in dataclasses.fields(dataclass_type):
if field_obj.metadata and "dps" in field_obj.metadata:
Expand Down
4 changes: 2 additions & 2 deletions roborock/mqtt/roborock_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import datetime
import logging
import ssl
from collections.abc import Callable
from collections.abc import AsyncIterator, Callable
from contextlib import asynccontextmanager

import aiomqtt
Expand Down Expand Up @@ -249,7 +249,7 @@ async def _run_connection(self, start_future: asyncio.Future[None] | None) -> No
raise

@asynccontextmanager
async def _mqtt_client(self, params: MqttParams) -> aiomqtt.Client:
async def _mqtt_client(self, params: MqttParams) -> AsyncIterator[aiomqtt.Client]:
"""Connect to the MQTT broker and listen for messages."""
_LOGGER.debug("Connecting to %s:%s for %s", params.host, params.port, params.username)
tls_params = None
Expand Down
5 changes: 3 additions & 2 deletions roborock/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,10 @@ def _parse(self, stream, context, path):
hash1 = self.checksumfield.parse_stream(stream, **context)
hash2 = self.hashfunc(self.bytesfunc(context))
if hash1 != hash2:
read_hex = binascii.hexlify(hash1).decode() if isinstance(hash1, bytestringtype) else hash1
computed_hex = binascii.hexlify(hash2).decode() if isinstance(hash2, bytestringtype) else hash2
raise ChecksumError(
f"wrong checksum, read {hash1 if not isinstance(hash1, bytestringtype) else binascii.hexlify(hash1)}, "
f"computed {hash2 if not isinstance(hash2, bytestringtype) else binascii.hexlify(hash2)}",
f"wrong checksum, read {read_hex}, computed {computed_hex}",
path=path,
)
return hash1
Expand Down
5 changes: 5 additions & 0 deletions tests/devices/traits/a01/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ async def test_dyad_api_query_values(dyad_api: DyadApi, fake_channel: FakeChanne
message = fake_channel.published_messages[0]
assert message.protocol == RoborockMessageProtocol.RPC_REQUEST
assert message.version == b"A01"
assert message.payload is not None
payload_data = json.loads(unpad(message.payload, AES.block_size))
assert payload_data["dps"] == {"10000": "[209, 201, 207, 214, 215, 227, 229, 230, 222, 224]"}
assert "t" in payload_data
Expand Down Expand Up @@ -408,6 +409,7 @@ async def test_zeo_api_query_values(zeo_api: ZeoApi, fake_channel: FakeChannel):
message = fake_channel.published_messages[0]
assert message.protocol == RoborockMessageProtocol.RPC_REQUEST
assert message.version == b"A01"
assert message.payload is not None
payload_data = json.loads(unpad(message.payload, AES.block_size))
assert payload_data["dps"] == {"10000": "[203, 207, 226, 227, 224, 218]"}
assert "t" in payload_data
Expand Down Expand Up @@ -479,6 +481,7 @@ async def test_dyad_api_set_value(dyad_api: DyadApi, fake_channel: FakeChannel):
assert message.version == b"A01"

# decode the payload to verify contents
assert message.payload is not None
payload_data = json.loads(unpad(message.payload, AES.block_size))
# A01 protocol expects values to be strings in the dps dict
assert payload_data["dps"] == {"209": 1}
Expand Down Expand Up @@ -534,6 +537,7 @@ async def test_dyad_action_commands(
await getattr(dyad_api, method)()

assert len(fake_channel.published_messages) == 1
assert fake_channel.published_messages[0].payload is not None
payload_data = json.loads(unpad(fake_channel.published_messages[0].payload, AES.block_size))
assert payload_data["dps"] == expected_dps

Expand All @@ -549,6 +553,7 @@ async def test_zeo_api_set_value(zeo_api: ZeoApi, fake_channel: FakeChannel):
assert message.version == b"A01"

# decode the payload to verify contents
assert message.payload is not None
payload_data = json.loads(unpad(message.payload, AES.block_size))
# A01 protocol expects values to be strings in the dps dict
assert payload_data["dps"] == {"204": "standard"}
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/web_api_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def home_data_fixture() -> dict[str, Any]:


@pytest.fixture(name="mock_rest")
def mock_rest_fixture(skip_rate_limit: Any, home_data: dict[str, Any]) -> aioresponses:
def mock_rest_fixture(skip_rate_limit: Any, home_data: dict[str, Any]) -> Generator[aioresponses, None, None]:
"""Mock all rest endpoints so they won't hit real endpoints"""
with aioresponses() as mocked:
# Match the base URL and allow any query params
Expand Down
2 changes: 1 addition & 1 deletion tests/map/test_b01_q10_map_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_packet_layers_decompose_q10_fixture() -> None:

living = layers.render_room(2, (255, 0, 0, 255))
image = Image.open(io.BytesIO(living))
opaque = sum(1 for *_rgb, alpha in image.getdata() if alpha > 0)
opaque = sum(1 for alpha in image.getchannel("A").tobytes() if alpha > 0)
assert opaque == next(room.pixel_count for room in layers.rooms if room.id == 2)


Expand Down
1 change: 1 addition & 0 deletions tests/protocols/test_a01_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def test_value_encoder():
result = encode_mqtt_payload(data, value_encoder=json.dumps)

# Decode manually to check the raw JSON structure
assert result.payload is not None
decoded_json = json.loads(unpad(result.payload, AES.block_size).decode())

# ID_QUERY (10000) should be a string "[101, 102]", not a list [101, 102]
Expand Down
33 changes: 33 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading