diff --git a/roborock/data/b01_q7/b01_q7_code_mappings.py b/roborock/data/b01_q7/b01_q7_code_mappings.py index df3f8cc0b..707a58c78 100644 --- a/roborock/data/b01_q7/b01_q7_code_mappings.py +++ b/roborock/data/b01_q7/b01_q7_code_mappings.py @@ -205,8 +205,9 @@ class B01Fault(RoborockModeEnum): ) # Docking error. Put the robot on the dock. Clear obstacles around the dock, clean charging contacts, and put # the robot on the dock. F_512 = ( - "docking_error", + "docking_error_512", 512, + "docking_error", ) # Docking error. Put the robot on the dock. Clear obstacles around the dock, clean charging contacts, and put # the robot on the dock. F_513 = ( @@ -214,14 +215,16 @@ class B01Fault(RoborockModeEnum): 513, ) # Robot trapped. Move the robot away and restart. Clear obstacles around robot or move robot away and restart. F_514 = ( - "robot_trapped", + "robot_trapped_514", 514, + "robot_trapped", ) # Robot trapped. Move the robot away and restart. Clear obstacles around robot or move robot away and restart. F_515 = ("fault_515", 515) F_517 = ("fault_517", 517) F_518 = ( - "low_battery", + "low_battery_518", 518, + "low_battery", ) # Low battery. Recharge now. Battery low. Put the robot on the dock to charge it to 20% before starting. F_519 = ("fault_519", 519) F_520 = ("fault_520", 520) @@ -258,10 +261,18 @@ class B01Fault(RoborockModeEnum): F_566 = ("fault_566", 566) F_567 = ("fault_567", 567) F_568 = ("main_wheels_entangled", 568) # Clean main wheels, move the robot away and restart. - F_569 = ("main_wheels_entangled", 569) # Clean main wheels, move the robot away and restart. + F_569 = ( + "main_wheels_entangled_569", + 569, + "main_wheels_entangled", + ) # Clean main wheels, move the robot away and restart. F_570 = ("main_brush_entangled", 570) # Main brush entangled. Remove and clean it and its bearing. F_571 = ("fault_571", 571) - F_572 = ("main_brush_entangled", 572) # Main brush entangled. Remove and clean it and its bearing. + F_572 = ( + "main_brush_entangled_572", + 572, + "main_brush_entangled", + ) # Main brush entangled. Remove and clean it and its bearing. F_573 = ("fault_573", 573) F_574 = ("fault_574", 574) F_580 = ("fault_580", 580) @@ -305,8 +316,9 @@ class B01Fault(RoborockModeEnum): 2007, ) # Unable to reach the target. Cleaning ended. Ensure the door to the target area is open or unobstructed. F_2012 = ( - "cannot_reach_target", + "cannot_reach_target_2012", 2012, + "cannot_reach_target", ) # Unable to reach the target. Cleaning ended. Ensure the door to the target area is open or unobstructed. F_2013 = ("fault_2013", 2013) F_2015 = ("fault_2015", 2015) diff --git a/roborock/data/b01_q7/b01_q7_containers.py b/roborock/data/b01_q7/b01_q7_containers.py index 6fa949175..89198080f 100644 --- a/roborock/data/b01_q7/b01_q7_containers.py +++ b/roborock/data/b01_q7/b01_q7_containers.py @@ -270,7 +270,7 @@ def status_name(self) -> str | None: @property def fault_name(self) -> str | None: """Returns the name of the current fault.""" - return self.fault.value if self.fault is not None else None + return self.fault.display_name if self.fault is not None else None @property def wind_name(self) -> str | None: diff --git a/tests/conformance/test_enum_conformance.py b/tests/conformance/test_enum_conformance.py index 90b928b2a..606ee6c2b 100644 --- a/tests/conformance/test_enum_conformance.py +++ b/tests/conformance/test_enum_conformance.py @@ -131,9 +131,7 @@ def test_roborock_mode_enum_handles_unknown_code(mode_enum_cls: type[RoborockMod # Legacy RoborockModeEnum classes whose members still share value strings. # As these enums are remediated, remove them from this baseline. -KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES = { - "roborock.data.b01_q7.b01_q7_code_mappings.B01Fault", -} +KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES: set[str] = set() _VALUE_ALIAS_XFAIL_MARKS = { fqn: pytest.mark.xfail(reason=f"{fqn} has members aliased by value", strict=True) diff --git a/tests/data/b01_q7/test_b01_q7_containers.py b/tests/data/b01_q7/test_b01_q7_containers.py index 8132d1df4..b5ff98fb7 100644 --- a/tests/data/b01_q7/test_b01_q7_containers.py +++ b/tests/data/b01_q7/test_b01_q7_containers.py @@ -43,6 +43,36 @@ def test_work_status_mapping(code: int, expected: WorkStatusMapping) -> None: assert WorkStatusMapping.from_code(code) is expected +@pytest.mark.parametrize( + ("code", "expected", "display_name"), + [ + (511, B01Fault.F_511, "docking_error"), + (512, B01Fault.F_512, "docking_error"), + (513, B01Fault.F_513, "robot_trapped"), + (514, B01Fault.F_514, "robot_trapped"), + (502, B01Fault.F_502, "low_battery"), + (518, B01Fault.F_518, "low_battery"), + (568, B01Fault.F_568, "main_wheels_entangled"), + (569, B01Fault.F_569, "main_wheels_entangled"), + (570, B01Fault.F_570, "main_brush_entangled"), + (572, B01Fault.F_572, "main_brush_entangled"), + (2007, B01Fault.F_2007, "cannot_reach_target"), + (2012, B01Fault.F_2012, "cannot_reach_target"), + ], +) +def test_b01props_fault_codes_sharing_a_name(code: int, expected: B01Fault, display_name: str) -> None: + """Faults that share a user-facing name each keep their own code.""" + deserialized = B01Props.from_dict({"fault": code}) + assert deserialized.fault is expected + assert deserialized.fault.code == code + assert deserialized.fault.display_name == display_name + assert deserialized.fault_name == display_name + keys = B01Fault.keys() + assert keys.count(display_name) == 1 + if expected.value != display_name: + assert expected.value not in keys + + def test_b01props_deserialization(): """Test that B01Props can be deserialized after its module is dynamically imported."""