Skip to content

fix(q7): stop B01Fault codes collapsing into aliases - #1074

Merged
allenporter merged 2 commits into
Python-roborock:mainfrom
anubhavlal07:fix/b01-fault-aliases
Nov 23, 2026
Merged

allenporter merged 2 commits into
Python-roborock:mainfrom
anubhavlal07:fix/b01-fault-aliases

Conversation

@anubhavlal07

@anubhavlal07 anubhavlal07 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Six members of B01Fault reuse another member's value string. These are F_512/F_511 docking_error, F_514/F_513 robot_trapped, F_518/F_502 low_battery, F_569/F_568 main_wheels_entangled, F_572/F_570 main_brush_entangled and F_2012/F_2007 cannot_reach_target. StrEnum silently 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 leaves fault as None. The conformance suite already tracked B01Fault in KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES for 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 to display_name. B01Fault.keys() still returns the same de-duplicated names. B01Fault is removed from the value-alias baseline, so the strict xfail now runs as a normal conformance check.

Tests

  • Added a parametrized test to tests/data/b01_q7/test_b01_q7_containers.py. It decodes each pair of faults that share a name and checks the member, code and display_name. The 6 new cases for the aliased codes fail on main and 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 unmodified main too.
  • ruff format, ruff check, mypy and codespell are 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 now False. Use fault.display_name (or B01Props.fault_name, which now returns it) when comparing by name.

Faults 512, 514, 518, 569, 572 and 2012 decoded as None.
Copilot AI balanced review requested due to automatic review settings November 22, 2026 09:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@saruk-vedant saruk-vedant left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 Lash-L left a comment

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.

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_name still returns self.fault.value instead of self.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 in display_name means B01Fault.keys() exposes only the de-duplicated display_name values (e.g., "docking_error"). However, B01Props.from_dict({"fault": 512}).fault_name now returns "docking_error_512", which is not in B01Fault.keys(). Downstream consumers that build enum options from B01Fault.keys() and read props.fault_name (e.g. Home Assistant SensorDeviceClass.ENUM sensors) will reject "docking_error_512" as an invalid option. Peer properties in v1_containers.py (error_code_name, state_name) and PR #993 (get_water_slide_mode_name, get_water_mode_mapping) all switched to .display_name for this exact reason.
    • Suggested Fix in roborock/data/b01_q7/b01_q7_containers.py:
           @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
      And assert deserialized.fault_name == display_name (plus display_name in B01Fault.keys() and expected.value not in B01Fault.keys() for the suffixed codes) in tests/data/b01_q7/test_b01_q7_containers.py.

Priority 2: Data Lifecycle & State Management — Clean

  • No lifecycle, state mutation, or concurrency regressions. Deserialization through RoborockBase._convert_to_class_obj calls B01Fault.from_code(value) cleanly for all 103 codes now that none are collapsed into StrEnum aliases.

Priority 3: Wire Protocols, Codecs & Resilient Enums — Clean

  • B01Fault inherits from RoborockModeEnum, all 103 members now have unique .value strings and unique .code integers, and removing B01Fault from KNOWN_MODE_ENUMS_WITH_VALUE_ALIASES in tests/conformance/test_enum_conformance.py promotes test_roborock_mode_enum_has_no_value_aliases from strict xfail to a normal passing conformance check.

Q7 App Bundle & Firmware Verification

  • Official Q7 Series Hermes App Bundle (FAULT_STATUS & localization tables):
    • All 103 B01Fault members (F_0 through F_2115) match the Q7 app's FAULT_STATUS enum 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_572 actually translates to "No-go zone or virtual wall detected" (检测到禁区或虚拟墙,请将主机搬离此区域) and fault_title_2012 to "Some areas cannot be reached" (部分区域无法到达,清洁结束), while the app's English locale reuses the 570/2007 strings. Keeping the existing display_name values here is the right call for backwards compatibility.
  • Q7 Firmware Dump: Verified no conflicting fault code definitions in the Q7 firmware images (record_faultcode passes 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

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.

@Lash-L Lash-L added /review run Code review skill (/review) has been run Q7 B01 Q7 platform labels Nov 22, 2026
@allenporter
allenporter merged commit dd74fa1 into Python-roborock:main Nov 23, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Q7 B01 Q7 platform /review run Code review skill (/review) has been run

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants