Repository navigation
fix(q7): stop B01Fault codes collapsing into aliases - #1074
Conversation
Faults 512, 514, 518, 569, 572 and 2012 decoded as None.
saruk-vedant
left a comment
There was a problem hiding this comment.
Thanks for picking this up, the fix is clean and matches the WaterModes approach from #993 exactly.
I checked the full B01Fault enum at this head: all 103 members now have unique values and unique codes, so the six pairs in the description are the only aliases and none were missed. The display_name on each second member matches the first member's value in all six cases, and the new test covers both members of every pair through B01Props.from_dict, including from_code(512), which raised before. Removing B01Fault from the conformance baseline is the right call too, since test_roborock_mode_enum_has_no_value_aliases now runs as a normal check for this enum.
One thing worth calling out in the PR description: this changes string comparison for the six second members. RoborockModeEnum.eq compares against the member value for strings, so B01Fault.F_512 == "docking_error" was True before and is False now, and str(F_512) is now "docking_error_512". I searched the repo and nothing in here compares against those strings, so it is not a blocker, but downstream consumers that match on the fault string could notice. Is that worth a note in the description?
Small suggestion, not blocking: the description says keys() still returns the same de-duplicated names, but nothing in the test pins that down. A short assertion that "docking_error" appears once in B01Fault.keys() and the suffixed values do not would lock in the user-facing contract the display_name move is meant to preserve.
Approving, the fix itself is correct and the test coverage is solid.
Lash-L
left a comment
There was a problem hiding this comment.
Automated code review by Gemini 4 Neon in Antigravity using our /review (/code-review) skill (.agents/skills/code-review/SKILL.md / AGENTS.md).
Summary by Architectural Layer
Priority 1: Public Trait APIs & Consumer Contracts — 1 Finding
roborock/data/b01_q7/b01_q7_containers.py(B01Props.fault_name, line 273) (not in diff):- Issue:
B01Props.fault_namestill returnsself.fault.valueinstead ofself.fault.display_name:@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
- Grounded Rationale: Giving the six previously aliased members distinct enum values (
docking_error_512,robot_trapped_514,low_battery_518,main_wheels_entangled_569,main_brush_entangled_572,cannot_reach_target_2012) while placing the canonical user-facing name indisplay_namemeansB01Fault.keys()exposes only the de-duplicateddisplay_namevalues (e.g.,"docking_error"). However,B01Props.from_dict({"fault": 512}).fault_namenow returns"docking_error_512", which is not inB01Fault.keys(). Downstream consumers that build enum options fromB01Fault.keys()and readprops.fault_name(e.g. Home AssistantSensorDeviceClass.ENUMsensors) will reject"docking_error_512"as an invalid option. Peer properties inv1_containers.py(error_code_name,state_name) and PR #993 (get_water_slide_mode_name,get_water_mode_mapping) all switched to.display_namefor this exact reason. - Suggested Fix in
roborock/data/b01_q7/b01_q7_containers.py:And assert@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 Nonedeserialized.fault_name == display_name(plusdisplay_name in B01Fault.keys()andexpected.value not in B01Fault.keys()for the suffixed codes) intests/data/b01_q7/test_b01_q7_containers.py.
- Issue:
Priority 2: Data Lifecycle & State Management — Clean
- No lifecycle, state mutation, or concurrency regressions. Deserialization through
RoborockBase._convert_to_class_objcallsB01Fault.from_code(value)cleanly for all 103 codes now that none are collapsed intoStrEnumaliases.
Priority 3: Wire Protocols, Codecs & Resilient Enums — Clean
B01Faultinherits fromRoborockModeEnum, all 103 members now have unique.valuestrings and unique.codeintegers, and removingB01FaultfromKNOWN_MODE_ENUMS_WITH_VALUE_ALIASESintests/conformance/test_enum_conformance.pypromotestest_roborock_mode_enum_has_no_value_aliasesfrom strictxfailto a normal passing conformance check.
Q7 App Bundle & Firmware Verification
- Official Q7 Series Hermes App Bundle (
FAULT_STATUS& localization tables):- All 103
B01Faultmembers (F_0throughF_2115) match the Q7 app'sFAULT_STATUSenum 1-for-1 with zero code mismatches. - All 6 split pairs are confirmed distinct wire codes in
FAULT_STATUS(511/512,513/514,502/518,568/569,570/572,2007/2012). Four pairs (502/518,511/512,513/514,568/569) share combined localization keys in the app (fault_title_502_518,fault_title_511_512,fault_title_513_514,fault_title_568_569), and the remaining two pairs (570/572,2007/2012) share identical English app strings ("Main brush entangled..."and"Unable to reach the target..."). - (Informational note, out of scope for this PR): In the Q7 app's Chinese (
zh) localization,fault_title_572actually translates to "No-go zone or virtual wall detected" (检测到禁区或虚拟墙,请将主机搬离此区域) andfault_title_2012to "Some areas cannot be reached" (部分区域无法到达,清洁结束), while the app's English locale reuses the570/2007strings. Keeping the existingdisplay_namevalues here is the right call for backwards compatibility.
- All 103
- Q7 Firmware Dump: Verified no conflicting fault code definitions in the Q7 firmware images (
record_faultcodepasses through the numeric fault codes).
Verdict
Almost ready — the enum un-aliasing and conformance baseline removal are clean and match #993, but B01Props.fault_name should be updated to return self.fault.display_name (with a corresponding test assertion) so the six newly decoded codes don't leak internal _* suffixes outside B01Fault.keys().
| deserialized = B01Props.from_dict({"fault": code}) | ||
| assert deserialized.fault is expected | ||
| assert deserialized.fault.code == code | ||
| assert deserialized.fault.display_name == display_name |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Bug
Six members of
B01Faultreuse another member's value string. These are F_512/F_511docking_error, F_514/F_513robot_trapped, F_518/F_502low_battery, F_569/F_568main_wheels_entangled, F_572/F_570main_brush_entangledand F_2012/F_2007cannot_reach_target.StrEnumsilently turns the later member into an alias of the first, so its code is lost. When a Q7 reports one of these faults,B01Fault.from_code(512)raises.B01Props.from_dict({"fault": 512})then logs a conversion error and leavesfaultasNone. The conformance suite already trackedB01FaultinKNOWN_MODE_ENUMS_WITH_VALUE_ALIASESfor this reason.Fix
This uses the same approach as #993 for
WaterModes. Each affected member gets its own value (docking_error_512, and so on), and the shared user-facing name moves todisplay_name.B01Fault.keys()still returns the same de-duplicated names.B01Faultis removed from the value-alias baseline, so the strict xfail now runs as a normal conformance check.Tests
tests/data/b01_q7/test_b01_q7_containers.py. It decodes each pair of faults that share a name and checks the member,codeanddisplay_name. The 6 new cases for the aliased codes fail onmainand pass with this change.uv run pytest --ignore=tests/e2e --ignore=tests/mqtt: 2568 passed, 46 xfailed. The MQTT broker and e2e tests hang or error on my Windows machine on unmodifiedmaintoo.ruff format,ruff check,mypyandcodespellare clean.Behaviour note: fault members that shared a name now have distinct values, so a string comparison such as
B01Fault.F_512 == "docking_error"is nowFalse. Usefault.display_name(orB01Props.fault_name, which now returns it) when comparing by name.