-
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 5 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,12 +28,15 @@ async def send_decoded_command( | |
| dps: int, | ||
| command: CommandType, | ||
| params: ParamsType, | ||
| ) -> dict[str, Any]: | ||
| """Send a command on the MQTT channel and get a decoded response.""" | ||
| ) -> Any: | ||
| """Send a command on the MQTT channel and get a decoded response. | ||
|
|
||
| Note: B01 "set" commands may return a scalar (e.g. 0/"ok") rather than a dict. | ||
| """ | ||
| _LOGGER.debug("Sending MQTT command: %s", params) | ||
| msg_id = str(get_next_int(100000000000, 999999999999)) | ||
| 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.""" | ||
|
|
@@ -58,20 +61,24 @@ def find_response(response_message: RoborockMessage) -> None: | |
| if isinstance(inner, dict) and inner.get("msgId") == msg_id: | ||
| _LOGGER.debug("Received query response: %s", inner) | ||
| 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("Unexpected data type for response")) | ||
| 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"Command timed out after {_TIMEOUT}s") from ex | ||
| except Exception as ex: | ||
|
Lash-L marked this conversation as resolved.
|
||
| _LOGGER.exception("Error sending decoded command: %s", ex) | ||
|
Lash-L marked this conversation as resolved.
Outdated
|
||
| raise | ||
| finally: | ||
| unsub() | ||
Uh oh!
There was an error while loading. Please reload this page.