Skip to content

Commit 71b785f

Browse files
committed
🦎 q7: restore command ack compatibility
1 parent 8303a8c commit 71b785f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

roborock/devices/rpc/b01_q7_channel.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def on_message(response_message: RoborockMessage) -> None:
6161
async def send_decoded_command(
6262
mqtt_channel: MqttChannel,
6363
request_message: Q7RequestMessage,
64-
) -> dict[str, Any]:
64+
) -> Any:
6565
"""Send a command on the MQTT channel and get a decoded response."""
6666
_LOGGER.debug("Sending B01 MQTT command: %s", request_message)
6767

68-
def find_response(response_message: RoborockMessage) -> dict[str, Any] | None:
68+
def find_response(response_message: RoborockMessage) -> Any | None:
6969
"""Handle incoming messages and resolve the future."""
7070
try:
7171
decoded_dps = decode_rpc_response(response_message)
@@ -97,7 +97,7 @@ def find_response(response_message: RoborockMessage) -> dict[str, Any] | None:
9797
_LOGGER.debug("B01 error response: %s", error_msg)
9898
raise RoborockException(error_msg)
9999
data = inner.get("data")
100-
if not isinstance(data, dict):
100+
if request_message.command == "prop.get" and not isinstance(data, dict):
101101
raise RoborockException(f"Unexpected data type for response {data} ({request_message})")
102102
return data
103103
return None

roborock/devices/traits/b01/q7/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"Q7MapListEntry",
3232
]
3333

34+
3435
class Q7PropertiesApi(Trait):
3536
"""API for interacting with B01 devices."""
3637

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Any
2+
from typing import Any, cast
33

44
import pytest
55
from Crypto.Cipher import AES
@@ -111,6 +111,19 @@ 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_allows_ok_string_ack(fake_channel: FakeChannel, message_builder: B01MessageBuilder):
115+
"""Command ACKs may return plain string payloads like ``ok``."""
116+
message = message_builder.build("ok")
117+
fake_channel.response_queue.append(message)
118+
119+
result = await send_decoded_command(
120+
cast(Any, fake_channel),
121+
Q7RequestMessage(dps=10000, command="service.set_room_clean", params=[]), # type: ignore[arg-type]
122+
)
123+
124+
assert result == "ok"
125+
126+
114127
async def test_q7_api_set_fan_speed(
115128
q7_api: Q7PropertiesApi, fake_channel: FakeChannel, message_builder: B01MessageBuilder
116129
):

0 commit comments

Comments
 (0)