Skip to content
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

fix json decode quirk for xiaomi e10 #1922

Merged
merged 3 commits into from
May 4, 2024
Merged

Conversation

matan-h
Copy link
Contributor

@matan-h matan-h commented Mar 31, 2024

Version:
Firmware version: 2.2.4_0050
Hardware version: esp32

some commands (e.g. genericmiot call map:rename-map '[0,"string"]') generate json-like string like this:

{"id":2,"result":,"exe_time":0}

and this produce the error:

ERROR:miio.protocol:Unable to parse json 'b'{"id":2,"result":,"exe_time":0}'': Expecting value: line 1 column 18 (char 17)
ERROR:miio.click_common:Exception: Unable to parse message payload

I fix that by removing the nonsense result":,.

Copy link

codecov bot commented Mar 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.45%. Comparing base (8643a57) to head (0eec5d8).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1922      +/-   ##
==========================================
+ Coverage   81.41%   81.45%   +0.03%     
==========================================
  Files         193      196       +3     
  Lines       18636    18891     +255     
  Branches     4045     4111      +66     
==========================================
+ Hits        15173    15387     +214     
- Misses       3180     3211      +31     
- Partials      283      293      +10     

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

@rytilahti
Copy link
Owner

Is the command still working, but just returning invalid json? Otherwise looks fine for me, thanks for the PR!

@matan-h
Copy link
Contributor Author

matan-h commented Mar 31, 2024

@rytilahti this is an interesting story. e10 is a cheap model that don't support maps. However, it still has the maps commands, just in a way no one can access them: there is only one map called "hello" with index 0, and according to the spec, map indexes start from one. So this corrupted json is the robot confused and returning empty result. (probably something like f"results:get_results(),exec_time:get_time()")

@rytilahti
Copy link
Owner

Heh, yeah, some firmware behave weirdly on error states, likely for the reason you mention. Would you mind adding a unit test similar as https://github.com/rytilahti/python-miio/blob/master/miio/tests/test_protocol.py#L129 for this quirk?

@rytilahti rytilahti added the bug label Mar 31, 2024
Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, @matan-h! I added a quick test and will merge this after the CI passes.

@rytilahti rytilahti merged commit 8bfe40d into rytilahti:master May 4, 2024
22 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants