Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions roborock/devices/a01_channel.py
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

Expand Down Expand Up @@ -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)
Copy link
Contributor

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_payload and (2) update the tests to verify at the mqtt channel level, decoding the Roborockmessage itself? The other caller of encode_mqtt_payload should probably push its logic down or we need to make it a flag or something to have that behavior.

except ValueError:
Copy link

Copilot AI Dec 7, 2025

Choose a reason for hiding this comment

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

Consider catching json.JSONDecodeError instead of ValueError for consistency with the rest of the codebase. While ValueError works (since JSONDecodeError is a subclass), other similar code in a01_protocol.py, b01_protocol.py, and v1_protocol.py all use json.JSONDecodeError for better clarity and specificity.

Suggested change
except ValueError:
except json.JSONDecodeError:

Copilot uses AI. Check for mistakes.
_LOGGER.warning("Failed to parse query values: %s", query_values)
return {}

# Merge any results together than contain the requested data. This
Copy link

Copilot AI Dec 7, 2025

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".

Suggested change
# Merge any results together than contain the requested data. This
# Merge any results together that contain the requested data. This

Copilot uses AI. Check for mistakes.
# does not use a future since it needs to merge results across responses.
# This could be simplified if we can assume there is a single response.
Expand Down
37 changes: 36 additions & 1 deletion tests/test_a01_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be somewhere under tests/devices/ instead?

"""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}