Skip to content

Handle non-object JSON responses as payload decode errors - #2093

Open
MaxRink wants to merge 2 commits into
rytilahti:masterfrom
MaxRink:fix-nonobject-miio-response-20261012
Open

MaxRink wants to merge 2 commits into
rytilahti:masterfrom
MaxRink:fix-nonobject-miio-response-20261012

Conversation

@MaxRink

@MaxRink MaxRink commented Oct 12, 2026

Copy link
Copy Markdown

Valid JSON device responses such as a list, null, or a string currently reach payload["id"] in MiIOProtocol.send and raise TypeError. Check that the decoded payload is a mapping and raise the existing PayloadDecodeException, so callers can handle it through DeviceException.

The regression tests use real encrypted message construction and Message.parse for each non-object JSON response, plus a valid object response to preserve normal result handling. Malformed JSON is already handled by the existing decoder and is unchanged.

Validation: 20 protocol tests passed; Ruff and git diff --check passed. This is a draft protocol robustness fix, with no Home Assistant deployment or device configuration changes.

@codecov

codecov Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.36%. Comparing base (9a00e08) to head (32f7a52).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2093      +/-   ##
==========================================
+ Coverage   84.31%   84.36%   +0.04%     
==========================================
  Files         201      201              
  Lines       20656    20659       +3     
  Branches     1121     1122       +1     
==========================================
+ Hits        17417    17429      +12     
+ Misses       3047     3036      -11     
- Partials      192      194       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@MaxRink
MaxRink marked this pull request as ready for review October 12, 2026 05:22
Copilot AI balanced review requested due to automatic review settings October 12, 2026 05:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused validation is correct and adequately covered by protocol-level regression tests.

0 open findings

What changed in this PR

Ensures non-object JSON device responses raise the established PayloadDecodeException instead of leaking TypeError.

Changes:

  • Validate decoded responses are mappings before accessing fields.
  • Add regression tests for invalid response shapes and valid objects.
File Description
miio/​miioprotocol.py Rejects non-object payloads with a device-level decode error.
miio/​tests/​test_protocol.py Tests list, null, string, and object responses.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

This branch has not been deployed

No deployments
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.

2 participants