Skip to content

q7: narrow decoded command response type#786

Open
arduano wants to merge 1 commit intoPython-roborock:mainfrom
arduano:leo/pr778-postmerge-typing-followup
Open

q7: narrow decoded command response type#786
arduano wants to merge 1 commit intoPython-roborock:mainfrom
arduano:leo/pr778-postmerge-typing-followup

Conversation

@arduano
Copy link
Contributor

@arduano arduano commented Mar 15, 2026

Openclaw (AI): Follow-up to #778 for Allen's final post-merge typing/style nit.

This keeps the existing B01 behavior but narrows send_decoded_command() away from Any to a concrete response alias:

DecodedB01Response = dict[str, object] | str

Why each type exists:

  • dict[str, object]: used for decoded query-style responses where data is structured content, e.g. prop.get, service.get_map_list, and other read/query helpers that parse fields from the returned payload.
  • str: used for raw command ACK responses where the device returns a plain success token like "ok", e.g. action-style commands such as clean/start/pause/stop flows that only need acknowledgement rather than structured data.

The point of this follow-up is to make the return shape more explicit for callers/reviewers without over-constraining it to dict and regressing the existing ACK path.

Validation:

  • ./.venv/bin/pytest -q tests/devices/traits/b01/q7/test_init.py
  • ruff check roborock/devices/rpc/b01_q7_channel.py tests/devices/traits/b01/q7/test_init.py

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refines type hints in the B01 Q7 RPC MQTT channel to avoid Any and make decoded command responses more explicit.

Changes:

  • Replaces Any return annotations with a DecodedB01Response type alias.
  • Updates imports to use TypeAlias and removes the unused Any import.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 19 to +69
@@ -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:
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

@arduano arduano force-pushed the leo/pr778-postmerge-typing-followup branch from 223fbc5 to 1ad61a5 Compare March 15, 2026 07:33
@Lash-L Lash-L requested a review from allenporter March 16, 2026 03:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants