|
7 | 7 | from roborock.data import CleanSummary |
8 | 8 | from roborock.devices.device import RoborockDevice |
9 | 9 | from roborock.devices.traits.v1.clean_summary import CleanSummaryTrait |
10 | | -from roborock.exceptions import RoborockException |
| 10 | +from roborock.exceptions import RoborockException, RoborockParsingException |
11 | 11 | from roborock.roborock_typing import RoborockCommand |
12 | 12 | from tests.mock_data import CLEAN_RECORD |
13 | 13 |
|
@@ -193,6 +193,58 @@ async def test_get_clean_record_success( |
193 | 193 | ) |
194 | 194 |
|
195 | 195 |
|
| 196 | +@pytest.mark.parametrize("response", [[], [[]]], ids=["empty", "wrapped-empty"]) |
| 197 | +async def test_get_clean_record_empty_response( |
| 198 | + clean_summary_trait: CleanSummaryTrait, mock_rpc_channel: AsyncMock, response: list |
| 199 | +) -> None: |
| 200 | + """Report empty records through the public parsing exception boundary.""" |
| 201 | + mock_rpc_channel.send_command.return_value = response |
| 202 | + |
| 203 | + with pytest.raises(RoborockParsingException, match="GET_CLEAN_RECORD") as exc: |
| 204 | + await clean_summary_trait.get_clean_record(1738864366) |
| 205 | + |
| 206 | + assert isinstance(exc.value.__cause__, ValueError) |
| 207 | + assert f"Payload: {response!r}" in str(exc.value) |
| 208 | + mock_rpc_channel.send_command.assert_called_once_with(RoborockCommand.GET_CLEAN_RECORD, params=[1738864366]) |
| 209 | + |
| 210 | + |
| 211 | +@pytest.mark.parametrize( |
| 212 | + "response", |
| 213 | + [ |
| 214 | + [CLEAN_RECORD], |
| 215 | + [ |
| 216 | + { |
| 217 | + "begin": 1700000000, |
| 218 | + "end": 1700000100, |
| 219 | + "duration": 100, |
| 220 | + "area": 1000000, |
| 221 | + "avoid_count": 1, |
| 222 | + "wash_count": 1, |
| 223 | + }, |
| 224 | + { |
| 225 | + "begin": 1700000200, |
| 226 | + "end": 1700000400, |
| 227 | + "duration": 200, |
| 228 | + "area": 2000000, |
| 229 | + "avoid_count": 2, |
| 230 | + "wash_count": 2, |
| 231 | + }, |
| 232 | + ], |
| 233 | + ], |
| 234 | + ids=["wrapped-dict", "multi-phase"], |
| 235 | +) |
| 236 | +async def test_get_clean_record_structured_responses( |
| 237 | + clean_summary_trait: CleanSummaryTrait, mock_rpc_channel: AsyncMock, response: list[dict] |
| 238 | +) -> None: |
| 239 | + """Keep wrapped and multi-phase records working through the public API.""" |
| 240 | + mock_rpc_channel.send_command.return_value = response |
| 241 | + |
| 242 | + record = await clean_summary_trait.get_clean_record(1738864366) |
| 243 | + |
| 244 | + assert record.begin == response[0]["begin"] |
| 245 | + assert record.end == response[-1]["end"] |
| 246 | + |
| 247 | + |
196 | 248 | async def test_get_clean_record_dict_response( |
197 | 249 | clean_summary_trait: CleanSummaryTrait, |
198 | 250 | mock_rpc_channel: AsyncMock, |
|
0 commit comments