Skip to content
Open
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
7 changes: 4 additions & 3 deletions roborock/devices/rpc/b01_q7_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import json
import logging
from collections.abc import Callable
from typing import Any, TypeVar
from typing import TypeAlias, TypeVar

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


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

def find_response(response_message: RoborockMessage) -> Any | None:
def find_response(response_message: RoborockMessage) -> DecodedB01Response | None:
Comment on lines 19 to +69
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this? Or just keep it simple

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What response types are we expecting? Will str actually happen anywhere? I see there is a special handling of prop.get, what happens in the other cases?

(I don't think just adding these all types is necessarily better than Any)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirmed, here's where str comes from:

mqtt_packet.gen_publish(test_topic, mid=2, payload=response_builder.build_b01_q7_rpc("ok", msg_id=9093)),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's real code that depends on strings though, it might just be those tests

"""Handle incoming messages and resolve the future."""
try:
decoded_dps = decode_rpc_response(response_message)
Expand Down
Loading