Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions roborock/data/b01_q7/b01_q7_code_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,26 @@ 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 = (
"robot_trapped",
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion roborock/data/b01_q7/b01_q7_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions tests/conformance/test_enum_conformance.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions tests/data/b01_q7/test_b01_q7_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Priority 1 (Consumer Contract): Please also assert deserialized.fault_name == display_name (and that B01Fault.keys() contains display_name without the _* suffixed values).

Currently B01Props.fault_name in roborock/data/b01_q7/b01_q7_containers.py:273 still returns self.fault.value instead of self.fault.display_name, so B01Props.from_dict({"fault": 512}).fault_name returns "docking_error_512" — a value not present in B01Fault.keys(). Updating B01Props.fault_name to self.fault.display_name (matching v1_containers.py and PR #993) and asserting it here locks in the user-facing contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d51f4da. I changed B01Props.fault_name to return self.fault.display_name, so from_dict({"fault": 512}).fault_name now gives "docking_error". The parametrized test now checks fault_name == display_name for all twelve codes. It also checks that each display name appears exactly once in B01Fault.keys() and that the _* suffixed values never appear there. Nothing else in the repo reads the Q7 fault_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."""

Expand Down
Loading