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
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
2 changes: 2 additions & 0 deletions miio/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ def _decode(self, obj, context, path) -> Union[Dict, bytes]:
),
# fix double commas for xiaomi.vacuum.b112, fw: 2.2.4_0049
lambda decrypted_bytes: decrypted_bytes.replace(b",,", b","),
# fix "result":," no sense key for xiaomi.vacuum.b112, fw:2.2.4_0050
lambda decrypted_bytes: decrypted_bytes.replace(b'"result":,', b""),
]

for i, quirk in enumerate(decrypted_quirks):
Expand Down
11 changes: 11 additions & 0 deletions miio/tests/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ def test_decode_json_quirk_cloud(token):
assert parsed_msg.data.value["id"] == 123456


def test_decode_json_empty_result(token):
"""Test for quirk handling on empty result seen with xiaomi.vacuum.b112."""
ctx = {"token": token}
serialized_msg = build_msg(b'{"id":2,"result":,"exe_time":0}', token)
parsed_msg = Message.parse(serialized_msg, **ctx)

assert parsed_msg.data.value
assert isinstance(parsed_msg.data.value, dict)
assert parsed_msg.data.value["id"] == 2


def test_decode_json_raises_for_invalid_json(token):
ctx = {"token": token}

Expand Down
Loading