-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add some basic setters for q7 #690
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
dccbe6b
5c16930
5db7ae4
e6fc646
d026b67
900ed38
80f9875
8680692
eda0a93
080d673
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,19 +28,31 @@ async def send_decoded_command( | |
| dps: int, | ||
| command: CommandType, | ||
| params: ParamsType, | ||
| ) -> dict[str, Any]: | ||
| ) -> dict | None: | ||
| """Send a command on the MQTT channel and get a decoded response.""" | ||
| _LOGGER.debug("Sending MQTT command: %s", params) | ||
| msg_id = str(get_next_int(100000000000, 999999999999)) | ||
| _LOGGER.debug( | ||
| "Sending B01 MQTT command: dps=%s method=%s msg_id=%s params=%s", | ||
| dps, | ||
| command, | ||
| msg_id, | ||
| params, | ||
| ) | ||
| roborock_message = encode_mqtt_payload(dps, command, params, msg_id) | ||
| future: asyncio.Future[dict[str, Any]] = asyncio.get_running_loop().create_future() | ||
| future: asyncio.Future[Any] = asyncio.get_running_loop().create_future() | ||
|
|
||
| def find_response(response_message: RoborockMessage) -> None: | ||
| """Handle incoming messages and resolve the future.""" | ||
| try: | ||
| decoded_dps = decode_rpc_response(response_message) | ||
| except RoborockException as ex: | ||
| _LOGGER.info("Failed to decode b01 message: %s: %s", response_message, ex) | ||
| _LOGGER.debug( | ||
| "Failed to decode B01 RPC response (expecting method=%s msg_id=%s): %s: %s", | ||
| command, | ||
| msg_id, | ||
| response_message, | ||
| ex, | ||
| ) | ||
| return | ||
|
|
||
| for dps_value in decoded_dps.values(): | ||
|
|
@@ -57,21 +69,50 @@ def find_response(response_message: RoborockMessage) -> None: | |
|
|
||
| if isinstance(inner, dict) and inner.get("msgId") == msg_id: | ||
| _LOGGER.debug("Received query response: %s", inner) | ||
| # Check for error code (0 = success, non-zero = error) | ||
| code = inner.get("code", 0) | ||
| if code != 0: | ||
| error_msg = ( | ||
| f"B01 command failed with code {code} " | ||
| f"(method={command}, msg_id={msg_id}, dps={dps}, params={params})" | ||
| ) | ||
| _LOGGER.debug("B01 error response: %s", error_msg) | ||
| if not future.done(): | ||
| future.set_exception(RoborockException(error_msg)) | ||
| return | ||
| data = inner.get("data") | ||
| # All get commands should be dicts | ||
| if command.endswith(".get") and not isinstance(data, dict): | ||
| if not future.done(): | ||
| future.set_exception( | ||
| RoborockException( | ||
| f"Unexpected data type for response " | ||
| f"(method={command}, msg_id={msg_id}, dps={dps}, params={params})" | ||
| ) | ||
| ) | ||
| return | ||
|
Comment on lines
+84
to
+93
|
||
| if not future.done(): | ||
| if isinstance(data, dict): | ||
| future.set_result(data) | ||
| else: | ||
| future.set_exception(RoborockException(f"Unexpected data type for response: {data}")) | ||
| future.set_result(data) | ||
|
|
||
| unsub = await mqtt_channel.subscribe(find_response) | ||
|
|
||
| _LOGGER.debug("Sending MQTT message: %s", roborock_message) | ||
| try: | ||
| await mqtt_channel.publish(roborock_message) | ||
| try: | ||
| return await asyncio.wait_for(future, timeout=_TIMEOUT) | ||
| except TimeoutError as ex: | ||
| raise RoborockException(f"Command timed out after {_TIMEOUT}s") from ex | ||
| return await asyncio.wait_for(future, timeout=_TIMEOUT) | ||
| except TimeoutError as ex: | ||
| raise RoborockException( | ||
| f"B01 command timed out after {_TIMEOUT}s (method={command}, msg_id={msg_id}, dps={dps}, params={params})" | ||
| ) from ex | ||
| except Exception as ex: | ||
|
Lash-L marked this conversation as resolved.
|
||
| _LOGGER.exception( | ||
| "Error sending B01 decoded command (method=%s msg_id=%s dps=%s params=%s): %s", | ||
| command, | ||
| msg_id, | ||
| dps, | ||
| params, | ||
| ex, | ||
| ) | ||
| raise | ||
| finally: | ||
| unsub() | ||
Uh oh!
There was an error while loading. Please reload this page.