Skip to content

Commit 43d30a9

Browse files
committed
🦎 q7: narrow decoded command response type
1 parent 6f9251f commit 43d30a9

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

roborock/devices/rpc/b01_q7_channel.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import json
77
import logging
88
from collections.abc import Callable
9-
from typing import Any, TypeVar
9+
from typing import TypeAlias, TypeVar
1010

1111
from roborock.devices.transport.mqtt_channel import MqttChannel
1212
from roborock.exceptions import RoborockException
@@ -16,6 +16,7 @@
1616
_LOGGER = logging.getLogger(__name__)
1717
_TIMEOUT = 10.0
1818
_T = TypeVar("_T")
19+
DecodedB01Response: TypeAlias = dict[str, object] | str
1920

2021

2122
def _matches_map_response(response_message: RoborockMessage, *, version: bytes | None) -> bytes | None:
@@ -61,11 +62,11 @@ def on_message(response_message: RoborockMessage) -> None:
6162
async def send_decoded_command(
6263
mqtt_channel: MqttChannel,
6364
request_message: Q7RequestMessage,
64-
) -> Any:
65+
) -> DecodedB01Response:
6566
"""Send a command on the MQTT channel and get a decoded response."""
6667
_LOGGER.debug("Sending B01 MQTT command: %s", request_message)
6768

68-
def find_response(response_message: RoborockMessage) -> Any | None:
69+
def find_response(response_message: RoborockMessage) -> DecodedB01Response | None:
6970
"""Handle incoming messages and resolve the future."""
7071
try:
7172
decoded_dps = decode_rpc_response(response_message)

tests/devices/traits/b01/q7/test_init.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ async def test_send_decoded_command_error_code(fake_channel: FakeChannel, messag
111111
await send_decoded_command(fake_channel, Q7RequestMessage(dps=10000, command="prop.get", params=[])) # type: ignore[arg-type]
112112

113113

114+
async def test_send_decoded_command_returns_dict_for_prop_get(
115+
fake_channel: FakeChannel, message_builder: B01MessageBuilder
116+
):
117+
"""Property queries still return decoded dict payloads."""
118+
message = message_builder.build({"status": 8})
119+
fake_channel.response_queue.append(message)
120+
121+
result = await send_decoded_command(
122+
cast(Any, fake_channel),
123+
Q7RequestMessage(dps=10000, command="prop.get", params=[]), # type: ignore[arg-type]
124+
)
125+
126+
assert result == {"status": 8}
127+
128+
114129
async def test_send_decoded_command_allows_ok_string_ack(fake_channel: FakeChannel, message_builder: B01MessageBuilder):
115130
"""Command ACKs may return plain string payloads like ``ok``."""
116131
message = message_builder.build("ok")

0 commit comments

Comments
 (0)