-
Notifications
You must be signed in to change notification settings - Fork 57
fix: handle different query types #650
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 all commits
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| """Thin wrapper around the MQTT channel for Roborock A01 devices.""" | ||||||
|
|
||||||
| import asyncio | ||||||
| import json | ||||||
| import logging | ||||||
| from typing import Any, overload | ||||||
|
|
||||||
|
|
@@ -54,6 +55,13 @@ async def send_decoded_command( | |||||
| await mqtt_channel.publish(roborock_message) | ||||||
| return {} | ||||||
|
|
||||||
| if isinstance(query_values, str): | ||||||
| try: | ||||||
| query_values = json.loads(query_values) | ||||||
| except ValueError: | ||||||
|
||||||
| except ValueError: | |
| except json.JSONDecodeError: |
Copilot
AI
Dec 7, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "than" should be "that".
| # Merge any results together than contain the requested data. This | |
| # Merge any results together that contain the requested data. This |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| from collections.abc import AsyncGenerator | ||
| from queue import Queue | ||
| from typing import Any | ||
| from unittest.mock import patch | ||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import paho.mqtt.client as mqtt | ||
| import pytest | ||
|
|
@@ -307,3 +307,38 @@ async def test_future_timeout( | |
| with patch("roborock.roborock_future.asyncio.timeout", side_effect=asyncio.TimeoutError): | ||
| data = await connected_a01_mqtt_client.update_values([RoborockZeoProtocol.STATE]) | ||
| assert data.get(RoborockZeoProtocol.STATE) is None | ||
|
|
||
|
|
||
| async def test_send_decoded_command_handles_stringified_query() -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be somewhere under |
||
| """Test that send_decoded_command handles ID_QUERY as a stringified list.""" | ||
| from roborock.devices.a01_channel import send_decoded_command | ||
| from roborock.devices.mqtt_channel import MqttChannel | ||
| from roborock.roborock_message import RoborockDyadDataProtocol, RoborockMessage, RoborockMessageProtocol | ||
|
|
||
| channel = MagicMock(spec=MqttChannel) | ||
| channel.publish = AsyncMock() | ||
|
|
||
| captured_callback = None | ||
|
|
||
| async def mock_subscribe(callback): | ||
| nonlocal captured_callback | ||
| captured_callback = callback | ||
| return lambda: None | ||
|
|
||
| channel.subscribe = AsyncMock(side_effect=mock_subscribe) | ||
|
|
||
| protocol_id = 101 | ||
| params = {RoborockDyadDataProtocol.ID_QUERY: str([protocol_id])} | ||
|
|
||
| task = asyncio.create_task(send_decoded_command(channel, params)) | ||
| await asyncio.sleep(0) | ||
|
|
||
| response_data = {"dps": {str(protocol_id): 123}} | ||
| payload = pad(json.dumps(response_data).encode("utf-8"), AES.block_size) | ||
| message = RoborockMessage(protocol=RoborockMessageProtocol.RPC_RESPONSE, payload=payload) | ||
|
|
||
| if captured_callback: | ||
| captured_callback(message) | ||
|
|
||
| result = await task | ||
| assert result == {protocol_id: 123} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is then undoing the str from
ZeoApi.query_values. That means we probably need to (1) revert that change in the trait, pass in the raw values here, then go back to encoding that inside ofencode_mqtt_payloadand (2) update the tests to verify at the mqtt channel level, decoding theRoborockmessageitself? The other caller ofencode_mqtt_payloadshould probably push its logic down or we need to make it a flag or something to have that behavior.