q7: narrow decoded command response type#786
q7: narrow decoded command response type#786arduano wants to merge 1 commit intoPython-roborock:mainfrom
Conversation
There was a problem hiding this comment.
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
Anyreturn annotations with aDecodedB01Responsetype alias. - Updates imports to use
TypeAliasand removes the unusedAnyimport.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @@ -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: | |||
There was a problem hiding this comment.
Should we do this? Or just keep it simple
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Just confirmed, here's where str comes from:
There was a problem hiding this comment.
Not sure if there's real code that depends on strings though, it might just be those tests
223fbc5 to
1ad61a5
Compare
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 fromAnyto a concrete response alias:DecodedB01Response = dict[str, object] | strWhy each type exists:
dict[str, object]: used for decoded query-style responses wheredatais 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
dictand regressing the existing ACK path.Validation:
./.venv/bin/pytest -q tests/devices/traits/b01/q7/test_init.pyruff check roborock/devices/rpc/b01_q7_channel.py tests/devices/traits/b01/q7/test_init.py