Skip to content

Commit dd74fa1

Browse files
authored
fix(q7): stop B01Fault codes collapsing into aliases (#1074)
* fix(q7): stop B01Fault codes collapsing into aliases Faults 512, 514, 518, 569, 572 and 2012 decoded as None. * fix(q7): return display_name from fault_name
1 parent 55fc81d commit dd74fa1

4 files changed

Lines changed: 50 additions & 10 deletions

File tree

‎roborock/data/b01_q7/b01_q7_code_mappings.py‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,26 @@ class B01Fault(RoborockModeEnum):
220220
) # Docking error. Put the robot on the dock. Clear obstacles around the dock, clean charging contacts, and put
221221
# the robot on the dock.
222222
F_512 = (
223-
"docking_error",
223+
"docking_error_512",
224224
512,
225+
"docking_error",
225226
) # Docking error. Put the robot on the dock. Clear obstacles around the dock, clean charging contacts, and put
226227
# the robot on the dock.
227228
F_513 = (
228229
"robot_trapped",
229230
513,
230231
) # Robot trapped. Move the robot away and restart. Clear obstacles around robot or move robot away and restart.
231232
F_514 = (
232-
"robot_trapped",
233+
"robot_trapped_514",
233234
514,
235+
"robot_trapped",
234236
) # Robot trapped. Move the robot away and restart. Clear obstacles around robot or move robot away and restart.
235237
F_515 = ("fault_515", 515)
236238
F_517 = ("fault_517", 517)
237239
F_518 = (
238-
"low_battery",
240+
"low_battery_518",
239241
518,
242+
"low_battery",
240243
) # Low battery. Recharge now. Battery low. Put the robot on the dock to charge it to 20% before starting.
241244
F_519 = ("fault_519", 519)
242245
F_520 = ("fault_520", 520)
@@ -273,10 +276,18 @@ class B01Fault(RoborockModeEnum):
273276
F_566 = ("fault_566", 566)
274277
F_567 = ("fault_567", 567)
275278
F_568 = ("main_wheels_entangled", 568) # Clean main wheels, move the robot away and restart.
276-
F_569 = ("main_wheels_entangled", 569) # Clean main wheels, move the robot away and restart.
279+
F_569 = (
280+
"main_wheels_entangled_569",
281+
569,
282+
"main_wheels_entangled",
283+
) # Clean main wheels, move the robot away and restart.
277284
F_570 = ("main_brush_entangled", 570) # Main brush entangled. Remove and clean it and its bearing.
278285
F_571 = ("fault_571", 571)
279-
F_572 = ("main_brush_entangled", 572) # Main brush entangled. Remove and clean it and its bearing.
286+
F_572 = (
287+
"main_brush_entangled_572",
288+
572,
289+
"main_brush_entangled",
290+
) # Main brush entangled. Remove and clean it and its bearing.
280291
F_573 = ("fault_573", 573)
281292
F_574 = ("fault_574", 574)
282293
F_580 = ("fault_580", 580)
@@ -320,8 +331,9 @@ class B01Fault(RoborockModeEnum):
320331
2007,
321332
) # Unable to reach the target. Cleaning ended. Ensure the door to the target area is open or unobstructed.
322333
F_2012 = (
323-
"cannot_reach_target",
334+
"cannot_reach_target_2012",
324335
2012,
336+
"cannot_reach_target",
325337
) # Unable to reach the target. Cleaning ended. Ensure the door to the target area is open or unobstructed.
326338
F_2013 = ("fault_2013", 2013)
327339
F_2015 = ("fault_2015", 2015)

‎roborock/data/b01_q7/b01_q7_containers.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def status_name(self) -> str | None:
270270
@property
271271
def fault_name(self) -> str | None:
272272
"""Returns the name of the current fault."""
273-
return self.fault.value if self.fault is not None else None
273+
return self.fault.display_name if self.fault is not None else None
274274

275275
@property
276276
def wind_name(self) -> str | None:

‎tests/conformance/test_enum_conformance.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@ def test_roborock_mode_enum_handles_unknown_code(mode_enum_cls: type[RoborockMod
131131

132132
# Legacy RoborockModeEnum classes whose members still share value strings.
133133
# As these enums are remediated, remove them from this baseline.
134-
KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES = {
135-
"roborock.data.b01_q7.b01_q7_code_mappings.B01Fault",
136-
}
134+
KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES: set[str] = set()
137135

138136
_VALUE_ALIAS_XFAIL_MARKS = {
139137
fqn: pytest.mark.xfail(reason=f"{fqn} has members aliased by value", strict=True)

‎tests/data/b01_q7/test_b01_q7_containers.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,36 @@ def test_work_status_mapping(code: int, expected: WorkStatusMapping) -> None:
4343
assert WorkStatusMapping.from_code(code) is expected
4444

4545

46+
@pytest.mark.parametrize(
47+
("code", "expected", "display_name"),
48+
[
49+
(511, B01Fault.F_511, "docking_error"),
50+
(512, B01Fault.F_512, "docking_error"),
51+
(513, B01Fault.F_513, "robot_trapped"),
52+
(514, B01Fault.F_514, "robot_trapped"),
53+
(502, B01Fault.F_502, "low_battery"),
54+
(518, B01Fault.F_518, "low_battery"),
55+
(568, B01Fault.F_568, "main_wheels_entangled"),
56+
(569, B01Fault.F_569, "main_wheels_entangled"),
57+
(570, B01Fault.F_570, "main_brush_entangled"),
58+
(572, B01Fault.F_572, "main_brush_entangled"),
59+
(2007, B01Fault.F_2007, "cannot_reach_target"),
60+
(2012, B01Fault.F_2012, "cannot_reach_target"),
61+
],
62+
)
63+
def test_b01props_fault_codes_sharing_a_name(code: int, expected: B01Fault, display_name: str) -> None:
64+
"""Faults that share a user-facing name each keep their own code."""
65+
deserialized = B01Props.from_dict({"fault": code})
66+
assert deserialized.fault is expected
67+
assert deserialized.fault.code == code
68+
assert deserialized.fault.display_name == display_name
69+
assert deserialized.fault_name == display_name
70+
keys = B01Fault.keys()
71+
assert keys.count(display_name) == 1
72+
if expected.value != display_name:
73+
assert expected.value not in keys
74+
75+
4676
def test_b01props_deserialization():
4777
"""Test that B01Props can be deserialized after its module is dynamically imported."""
4878

0 commit comments

Comments
 (0)