Skip to content

Conversation

@Lash-L
Copy link
Collaborator

@Lash-L Lash-L commented Dec 7, 2025

This fixes A01 devices. Open to tweaks as needed. I believe it will always be a string now? But a check is probably the safest thing rn.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the A01 device handling where query values can be received as stringified JSON instead of native Python lists. The fix adds JSON deserialization logic to handle this case gracefully.

  • Adds JSON parsing to handle stringified query values in send_decoded_command
  • Includes comprehensive test coverage for the new string-to-list conversion functionality
  • Logs a warning and returns empty dict when JSON parsing fails

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
roborock/devices/a01_channel.py Adds string type check and JSON parsing logic to handle stringified query values before processing
tests/test_a01_api.py Adds test case to verify correct handling of stringified ID_QUERY values and adds necessary mock imports

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

if isinstance(query_values, str):
try:
query_values = json.loads(query_values)
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.
@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

❌ Patch coverage is 86.66667% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
roborock/devices/a01_channel.py 57.14% 3 Missing ⚠️
tests/test_a01_api.py 95.65% 0 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
tests/test_a01_api.py 99.22% <95.65%> (-0.78%) ⬇️
roborock/devices/a01_channel.py 68.00% <57.14%> (-1.77%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.


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.

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?

@allenporter
Copy link
Contributor

I sent #651 which is partial rollback of the PR that introduced the bug, doing it another way

@Lash-L Lash-L closed this Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants