diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 57e8d8904..435d29cec 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: diff --git a/mypy.ini b/mypy.ini deleted file mode 100644 index ebf1c85a0..000000000 --- a/mypy.ini +++ /dev/null @@ -1,8 +0,0 @@ -[mypy] -check_untyped_defs = True - -[mypy-construct] -ignore_missing_imports = True - -[mypy-roborock.cli] -ignore_errors = True diff --git a/pyproject.toml b/pyproject.toml index 0c8d4171b..4beb34a71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", @@ -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] diff --git a/roborock/data/containers.py b/roborock/data/containers.py index cca9466d7..97398088d 100644 --- a/roborock/data/containers.py +++ b/roborock/data/containers.py @@ -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 diff --git a/roborock/devices/traits/common.py b/roborock/devices/traits/common.py index 35a6220ef..78dc0d7b7 100644 --- a/roborock/devices/traits/common.py +++ b/roborock/devices/traits/common.py @@ -77,7 +77,7 @@ 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 @@ -85,7 +85,7 @@ def __init__(self, dps_type_map: dict[TDps, type], dps_field_map: dict[TDps, str @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: diff --git a/roborock/mqtt/roborock_session.py b/roborock/mqtt/roborock_session.py index a64992718..5871ca775 100644 --- a/roborock/mqtt/roborock_session.py +++ b/roborock/mqtt/roborock_session.py @@ -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 @@ -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 diff --git a/roborock/protocol.py b/roborock/protocol.py index 4b771b712..4ba051166 100644 --- a/roborock/protocol.py +++ b/roborock/protocol.py @@ -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 diff --git a/tests/devices/traits/a01/test_init.py b/tests/devices/traits/a01/test_init.py index aea824e6f..925b02024 100644 --- a/tests/devices/traits/a01/test_init.py +++ b/tests/devices/traits/a01/test_init.py @@ -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 @@ -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 @@ -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} @@ -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 @@ -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"} diff --git a/tests/fixtures/web_api_fixtures.py b/tests/fixtures/web_api_fixtures.py index c52c829a0..ef9b7da91 100644 --- a/tests/fixtures/web_api_fixtures.py +++ b/tests/fixtures/web_api_fixtures.py @@ -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 diff --git a/tests/map/test_b01_q10_map_parser.py b/tests/map/test_b01_q10_map_parser.py index 6d2c55376..5b4a416b4 100644 --- a/tests/map/test_b01_q10_map_parser.py +++ b/tests/map/test_b01_q10_map_parser.py @@ -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) diff --git a/tests/protocols/test_a01_protocol.py b/tests/protocols/test_a01_protocol.py index f60cfdff3..034fe355a 100644 --- a/tests/protocols/test_a01_protocol.py +++ b/tests/protocols/test_a01_protocol.py @@ -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] diff --git a/uv.lock b/uv.lock index 2dbeb86e4..bdb08c5e6 100644 --- a/uv.lock +++ b/uv.lock @@ -1396,6 +1396,9 @@ dev = [ { name = "python-roborock", extra = ["cli"] }, { name = "ruff" }, { name = "syrupy" }, + { name = "types-paho-mqtt" }, + { name = "types-protobuf" }, + { name = "types-pyyaml" }, { name = "zmqtt" }, ] @@ -1434,6 +1437,9 @@ dev = [ { name = "python-roborock", extras = ["cli"] }, { name = "ruff", specifier = "==0.14.11" }, { name = "syrupy", specifier = ">=4.9.1,<6" }, + { name = "types-paho-mqtt" }, + { name = "types-protobuf" }, + { name = "types-pyyaml" }, { name = "zmqtt", specifier = ">=0.2.0,<0.3.0" }, ] @@ -1597,6 +1603,33 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/77/b8/0135fadc89e73be292b473cb820b4f5a08197779206b33191e801feeae40/tomli-2.3.0-py3-none-any.whl", hash = "sha256:e95b1af3c5b07d9e643909b5abbec77cd9f1217e6d0bca72b0234736b9fb1f1b", size = 14408, upload-time = "2025-10-08T22:01:46.04Z" }, ] +[[package]] +name = "types-paho-mqtt" +version = "1.6.0.20240321" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/a6/2e/8836d327c52dd8818a6c61e976a627f04e68f11dc2e9980b70e7ce447475/types-paho-mqtt-1.6.0.20240321.tar.gz", hash = "sha256:694eec160340f2a2b151237dcc3f107a63e1c4e5b8f9fcda0ba392049af9cbec", size = 8173, upload-time = "2024-03-21T02:15:17.779Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/92/60/bd4d0cf58c7d7bbeed3c0043647f3b7b6ea0c27fd9cfd54dfdea4927bbc6/types_paho_mqtt-1.6.0.20240321-py3-none-any.whl", hash = "sha256:cd275c14f39363c2a0f8286ead9a46962e5421ebd477547b892ae016699f5a4a", size = 9260, upload-time = "2024-03-21T02:15:16.712Z" }, +] + +[[package]] +name = "types-protobuf" +version = "7.35.1.20260906" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/e1/6c/e3e5b3e10bc328126a39637c138f9ebfd734bf14342b9f3540039b4ab995/types_protobuf-7.35.1.20260906.tar.gz", hash = "sha256:efd1a3862d4c967dad5512ef8d56b1530ac84f182c41735b94004756518c4998", size = 69895, upload-time = "2026-09-06T06:35:28.308Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/44/4e/f63e826c68f77ef875506d72f225918800346545ee99847bc28f3394f18d/types_protobuf-7.35.1.20260906-py3-none-any.whl", hash = "sha256:5155e48569e0dabff303fdf578db96cd31ea9a4a63b18018a4ceac6b0ae17462", size = 86419, upload-time = "2026-09-06T06:35:27.247Z" }, +] + +[[package]] +name = "types-pyyaml" +version = "6.0.12.20261113" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/4d/8b/ba599d956693dbc98e170f32097128bdea0a17f9d42b0b490fa749c12b1a/types_pyyaml-6.0.12.20261113.tar.gz", hash = "sha256:0828be2580fd94151182364f4d0158e4de62fdbeeb8d4296f7f7d2b6c22bb640", size = 19017, upload-time = "2026-11-13T08:51:21.488Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/fd/2e/36fc0941a40ef066dbc8abac41bbbefb41389f547c779aef832aea6b873d/types_pyyaml-6.0.12.20261113-py3-none-any.whl", hash = "sha256:3600749e613748afdc4327f0b17c3296cf880cdbc7335f320007abd9dd815f67", size = 21321, upload-time = "2026-11-13T08:51:20.417Z" }, +] + [[package]] name = "typing-extensions" version = "4.15.0"