|
7 | 7 | from Crypto.Util.Padding import pad, unpad |
8 | 8 |
|
9 | 9 | from roborock.data.b01_q7 import WorkStatusMapping |
| 10 | +from roborock.devices.b01_channel import send_decoded_command |
10 | 11 | from roborock.devices.traits.b01.q7 import Q7PropertiesApi |
| 12 | +from roborock.exceptions import RoborockException |
11 | 13 | from roborock.protocols.b01_protocol import B01_VERSION |
12 | 14 | from roborock.roborock_message import RoborockB01Props, RoborockMessage, RoborockMessageProtocol |
13 | 15 | from tests.conftest import FakeChannel |
@@ -87,6 +89,7 @@ async def test_q7_api_query_values(q7_api: Q7PropertiesApi, fake_channel: FakeCh |
87 | 89 | assert message.version == B01_VERSION |
88 | 90 |
|
89 | 91 | # Verify request payload |
| 92 | + assert message.payload is not None |
90 | 93 | payload_data = json.loads(unpad(message.payload, AES.block_size)) |
91 | 94 | # {"dps": {"10000": {"method": "prop.get", "msgId": "123456789", "params": {"property": ["status", "wind"]}}}} |
92 | 95 | assert "dps" in payload_data |
@@ -128,3 +131,36 @@ async def test_q7_response_value_mapping( |
128 | 131 | result = await q7_api.query_values(query) |
129 | 132 |
|
130 | 133 | assert result is not None |
| 134 | + |
| 135 | + |
| 136 | +async def test_send_decoded_command_non_dict_response(fake_channel: FakeChannel): |
| 137 | + """Test validity of handling non-dict responses (should not timeout).""" |
| 138 | + msg_id = "123456789" |
| 139 | + |
| 140 | + dps_payload = { |
| 141 | + "dps": { |
| 142 | + "10000": json.dumps( |
| 143 | + { |
| 144 | + "msgId": msg_id, |
| 145 | + "data": "some_string_error", |
| 146 | + } |
| 147 | + ) |
| 148 | + } |
| 149 | + } |
| 150 | + message = RoborockMessage( |
| 151 | + protocol=RoborockMessageProtocol.RPC_RESPONSE, |
| 152 | + payload=pad( |
| 153 | + json.dumps(dps_payload).encode(), |
| 154 | + AES.block_size, |
| 155 | + ), |
| 156 | + version=b"B01", |
| 157 | + seq=2021, |
| 158 | + ) |
| 159 | + |
| 160 | + fake_channel.response_queue.append(message) |
| 161 | + |
| 162 | + with patch("roborock.devices.b01_channel.get_next_int", return_value=int(msg_id)): |
| 163 | + # Use a random string for command type to avoid needing import |
| 164 | + |
| 165 | + with pytest.raises(RoborockException, match="Unexpected data type for response"): |
| 166 | + await send_decoded_command(fake_channel, 10000, "prop.get", []) # type: ignore[arg-type] |
0 commit comments