|
12 | 12 | CleanRecordDetail, |
13 | 13 | CleanRecordList, |
14 | 14 | CleanRepeatMapping, |
| 15 | + DustCollectionStateMapping, |
15 | 16 | SCWindMapping, |
| 17 | + StationStateMapping, |
16 | 18 | WorkStatusMapping, |
17 | 19 | ) |
18 | 20 | from roborock.data.code_mappings import completed_warnings |
@@ -179,6 +181,55 @@ def test_b01props_deserialization_unknown_work_status(caplog: pytest.LogCaptureF |
179 | 181 | assert "Failed to convert status" not in caplog.text |
180 | 182 |
|
181 | 183 |
|
| 184 | +@pytest.mark.parametrize("station_key,dust_key", [("station_act", "dust_action"), ("stationAct", "dustAction")]) |
| 185 | +@pytest.mark.parametrize( |
| 186 | + ("station_code", "dust_code", "expected_station", "expected_dust"), |
| 187 | + [ |
| 188 | + (0, 0, StationStateMapping.idle, DustCollectionStateMapping.idle), |
| 189 | + (3, 1, StationStateMapping.collecting_dust, DustCollectionStateMapping.collecting_dust), |
| 190 | + ], |
| 191 | +) |
| 192 | +def test_b01props_dock_states( |
| 193 | + station_key: str, |
| 194 | + dust_key: str, |
| 195 | + station_code: int, |
| 196 | + dust_code: int, |
| 197 | + expected_station: StationStateMapping, |
| 198 | + expected_dust: DustCollectionStateMapping, |
| 199 | +) -> None: |
| 200 | + """Decode dock states and preserve integer values when serializing them.""" |
| 201 | + props = B01Props.from_dict({station_key: station_code, dust_key: dust_code}) |
| 202 | + |
| 203 | + assert props.station_act is expected_station |
| 204 | + assert props.dust_action is expected_dust |
| 205 | + serialized = json.loads(json.dumps(props.as_dict())) |
| 206 | + assert serialized == {"stationAct": station_code, "dustAction": dust_code} |
| 207 | + restored = B01Props.from_dict(serialized) |
| 208 | + assert restored.station_act is expected_station |
| 209 | + assert restored.dust_action is expected_dust |
| 210 | + |
| 211 | + |
| 212 | +@pytest.mark.parametrize("station_code,dust_code", [(-1, -1), (1, 2), (999, 999)]) |
| 213 | +def test_b01props_unknown_dock_states(station_code: int, dust_code: int, caplog: pytest.LogCaptureFixture) -> None: |
| 214 | + """Unknown dock states must not appear idle or discard other properties.""" |
| 215 | + props = B01Props.from_dict({"station_act": station_code, "dust_action": dust_code, "quantity": 87}) |
| 216 | + |
| 217 | + assert props.station_act is StationStateMapping.unknown |
| 218 | + assert props.dust_action is DustCollectionStateMapping.unknown |
| 219 | + assert props.quantity == 87 |
| 220 | + assert "Failed to convert" not in caplog.text |
| 221 | + |
| 222 | + |
| 223 | +@pytest.mark.parametrize("payload", [{}, {"station_act": None, "dust_action": None}]) |
| 224 | +def test_b01props_missing_dock_states(payload: dict[str, None]) -> None: |
| 225 | + """Missing dock states stay absent rather than becoming idle or unknown.""" |
| 226 | + props = B01Props.from_dict(payload) |
| 227 | + |
| 228 | + assert props.station_act is None |
| 229 | + assert props.dust_action is None |
| 230 | + assert props.as_dict() == {} |
| 231 | + |
| 232 | + |
182 | 233 | def test_b01_q7_clean_record_list_parses_detail_fields(): |
183 | 234 | payload = { |
184 | 235 | "total_time": 34980, |
|
0 commit comments