Skip to content

Commit 7b5688c

Browse files
committed
chore: Improve test coverage for invalid pessage parsing
1 parent 7a73268 commit 7b5688c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

roborock/protocols/b01_q10_protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ def _convert_datapoints(datapoints: dict[str, Any], message: RoborockMessage) ->
4040
code = int(key)
4141
except ValueError as e:
4242
raise ValueError(f"dps key is not a valid integer: {e} for {message.payload!r}") from e
43-
dps = B01_Q10_DP.from_code(code)
43+
try:
44+
dps = B01_Q10_DP.from_code(code)
45+
except ValueError as e:
46+
raise ValueError(f"dps key is not a valid B01_Q10_DP: {e} for {message.payload!r}") from e
4447
result[dps] = value
4548
return result
4649

tests/protocols/test_b01_q10_protocol.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_decode_rpc_payload(filename: str, snapshot: SnapshotAssertion) -> None:
5858
(b'{"dps": {"not_a_number": 123}}', "dps key is not a valid integer"),
5959
(b'{"dps": {"101": 123}}', "Invalid dpCommon format: expected dict"),
6060
(b'{"dps": {"101": {"not_a_number": 123}}}', "Invalid dpCommon format: dps key is not a valid intege"),
61+
(b'{"dps": {"909090": 123}}', "dps key is not a valid B01_Q10_DP"),
6162
],
6263
)
6364
def test_decode_invalid_rpc_payload(payload: bytes, expected_error_message: str) -> None:

0 commit comments

Comments
 (0)