Skip to content

fix: decode product families when generating feature docs - #1033

Merged
allenporter merged 3 commits into
Python-roborock:mainfrom
hCoureau:fix/feature-docs-nickname-decoding
Nov 23, 2026
Merged

allenporter merged 3 commits into
Python-roborock:mainfrom
hCoureau:fix/feature-docs-nickname-decoding

Conversation

@hCoureau

@hCoureau hCoureau commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

The feature-doc generator passes YAML nickname strings into a decoder keyed by RoborockProductNickname, so family-derived flags differ from runtime decoding. Explicit family names now resolve to enum members, and unknown names produce an error before the output is written. Missing, empty, and Unknown family values use the runtime model lookup, including its PEARLPLUS fallback for unrecognised models.

The generator decodes V1 capability flags for V1 devices and legacy entries with no protocol. A01 and B01 devices keep their columns and raw metadata. The table uses declared boolean fields for decoded capabilities and preserves the raw flag values. SUPPORTED_FEATURES.md was regenerated from the current catalogue and Home API fixtures.

CLI tests cover an explicit nickname overriding the fallback, nonzero raw flag preservation and decoding, and protocol gating. The local unit suite passed on Python 3.11 and 3.14 with 2,692 passing tests on each. Pre-commit, commitlint, and the source and wheel builds passed. Repeated generation produced byte-identical output.

Related to #1016.

@hCoureau
hCoureau marked this pull request as ready for review November 11, 2026 19:55
@Lash-L Lash-L added bug Something isn't working V1 V1 platform labels Nov 15, 2026

@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: No changes to public traits, domain models, or consumer contracts.
  • Priority 2 — Data Lifecycle & State Management: Only tests/devices/test_device_manager.py is touched (test_start_connect_failure). Waiting on ready_callback via asyncio.Event (instead of polling is_connected, which can become True when the channel subscribes before v1_properties.start() finishes) and closing device_manager in a finally block is a sound fix for the CI race.
  • Priority 3 — Wire Protocols, Codecs & Cryptography: No wire protocol or codec changes.
  • CLI Tooling, Generated Docs & Tests (roborock/cli.py, SUPPORTED_FEATURES.md, tests/test_cli.py):
    • update_docs now resolves YAML product_nickname strings to RoborockProductNickname enum members and fails fast with click.ClickException on invalid names before writing output.
    • When product_nickname is None, "", or "Unknown", the fallback (SHORT_MODEL_TO_ENUM.get(model.split(".")[-1], RoborockProductNickname.PEARLPLUS)) matches runtime HomeDataProduct.product_nickname / DeviceData.product_nickname in roborock/data/containers.py.
    • Filtering features_dict to bool values prevents raw diagnostic fields on DeviceFeatures (new_feature_info, new_feature_info_str, feature_info) from overwriting metadata rows with X or emitting a spurious feature_info row.
    • SUPPORTED_FEATURES.md is cleanly regenerated and tests/test_cli.py verifies parity directly against HomeDataProduct.product_nickname and DeviceFeatures.from_feature_flags.

Verdict

Ready to approve — no blocking defects found and all CI checks pass. One minor non-blocking PR scoping note is attached inline regarding the unrelated reconnect test fix (b10bbe5).

ready_devices: list[RoborockDevice] = []
device_manager = await create_device_manager(USER_PARAMS, ready_callback=ready_devices.append)
devices = await device_manager.get_devices()
ready = asyncio.Event()

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.

PR Scoping (non-blocking): Per AGENTS.md §6 (PR Hygiene & Sizing), commit b10bbe5 (fix: wait for device readiness in reconnect test) addresses an unrelated subsystem compared to the CLI feature-doc generator fix in this PR.

The fix itself is sound (self._channel.subscribe() sets is_connected before v1_properties.start() completes and _ready_callbacks fires, and try...finally ensures teardown), so this is fine to merge as-is if maintainers prefer, or can be split into a separate PR to keep history scoped.

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.

Good call. I've dropped that commit from this PR and opened it separately as #1071.

@Lash-L Lash-L added /review run Code review skill (/review) has been run Passed /review Passed the /review skill check labels Nov 21, 2026

@allenporter allenporter 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 splitting out #1071 and cleaning up the update-docs nickname decoding! The core fix and test coverage look good, and I left a few inline notes below:

  1. Non-V1 protocol gating in update_docs(): Gating V1 DeviceFeatures decoding on protocol_version avoids attributing 10 V1 vacuum PEARLPLUS features to B01 vacuums and the A01 washing machine (roborock.wm.a102) in SUPPORTED_FEATURES.md.
  2. Field-type filtering (non-blocking): Filtering by fields(DeviceFeatures) (f.type is bool) instead of runtime isinstance(is_supported, bool) avoids the bool-as-int edge case on roborock.vacuum.a27 (new_feature_info: False).
  3. Test coverage polish (non-blocking): Two small suggestions in tests/test_cli.py to exercise the explicit YAML nickname override happy path and truthy new_feature_info preservation.

Minor housekeeping: the PR description still mentions the reconnect test fix that was moved to #1071.

Comment thread roborock/cli.py Outdated
Comment on lines 1318 to 1331
nickname_name = data.get("product_nickname")
product_nickname = SHORT_MODEL_TO_ENUM.get(model.split(".")[-1], RoborockProductNickname.PEARLPLUS)
if nickname_name not in (None, "", "Unknown"):
try:
product_nickname = RoborockProductNickname[nickname_name]
except KeyError as err:
raise click.ClickException(f"Unknown product nickname {nickname_name!r} for {model}") from err
# Reconstruct the DeviceFeatures object from the raw data in the YAML file
device_features = DeviceFeatures.from_feature_flags(
new_feature_info=data.get("new_feature_info", 0),
new_feature_info_str=data.get("new_feature_info_str", ""),
feature_info=data.get("feature_info", []),
product_nickname=data.get("product_nickname", ""),
product_nickname=product_nickname,
)

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.

Protocol isolation / SUPPORTED_FEATURES.md accuracy: DeviceFeatures.from_feature_flags is only used by DeviceFeaturesTrait on V1 (pv == "1.0") devices at runtime. Running it unconditionally here with the PEARLPLUS fallback gives B01 vacuums (sc01, sc05, ss07) and the A01 Zeo One washing machine (roborock.wm.a102) 10 V1 vacuum features in SUPPORTED_FEATURES.md (adding 8 new X cells such as is_ai_recognition_obstacle_supported, is_pure_clean_mop_supported, is_max_plus_mode_supported, is_clean_route_setting_supported, etc.).

Since protocol_version is already present in data, gating V1 feature decoding on data.get("protocol_version") in (None, "", "1.0") keeps non-V1 devices in the table with their metadata rows without fabricating V1 vacuum capabilities for them.

Comment thread roborock/cli.py Outdated
Comment on lines +1343 to +1345
for feature, is_supported in features_dict.items():
if not isinstance(is_supported, bool):
continue

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.

Non-blocking: Filtering by runtime value type (isinstance(is_supported, bool)) does not exclude new_feature_info when YAML supplies a boolean—which actually happens for roborock.vacuum.a27 (new_feature_info: False) in device_info.yaml. It happens to be harmless today only because False is falsy and special_rows subtracts new_feature_info later.

Matching DeviceFeatures.from_dict (roborock/device_features.py) by iterating over declared boolean fields ([f.name for f in fields(DeviceFeatures) if f.type is bool]) avoids both the bool-is-int edge case and the asdict() copy.

Comment thread tests/test_cli.py
Comment on lines +26 to +36
[
("PEARLPLUS", "a87"),
("TANOS", "s6"),
("ULTRONLITE", "a73"),
("Unknown", "test"),
("", "test"),
(None, "test"),
("Unknown", "s6"),
("", "s6"),
(None, "s6"),
],

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.

Non-blocking: In the three named cases (("PEARLPLUS", "a87"), ("TANOS", "s6"), ("ULTRONLITE", "a73")), short_model already maps to the exact same enum in SHORT_MODEL_TO_ENUM, so all 9 cases would still pass even if the RoborockProductNickname[nickname_name] branch were removed. Adding a case where an explicit YAML nickname overrides an unmapped model's PEARLPLUS fallback (e.g., ("TANOS", "test") asserting RoborockProductNickname.TANOS) would directly cover that happy path.

Comment thread tests/test_cli.py Outdated
{
model: {
"product_nickname": nickname_name,
"new_feature_info": 0,

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.

Non-blocking: Because 0 is falsy, assert rows["new_feature_info"] == "0" would pass even without the non-bool filter (unlike "new_feature_info_str": "0", which is truthy and does catch the overwrite bug). Using a non-zero integer (e.g., 16) verifies both raw new_feature_info preservation and bitflag decoding.

@allenporter
allenporter marked this pull request as draft November 22, 2026 03:01
Merge upstream main and regenerate the capability table. Address review feedback by decoding V1 flags only for V1 and legacy entries, selecting declared boolean fields, and covering family overrides and nonzero flags.
@hCoureau
hCoureau marked this pull request as ready for review November 22, 2026 20:41
@allenporter
allenporter merged commit 3077c7f into Python-roborock:main Nov 23, 2026
9 checks passed
@hCoureau
hCoureau deleted the fix/feature-docs-nickname-decoding branch November 23, 2026 22:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Passed /review Passed the /review skill check /review run Code review skill (/review) has been run V1 V1 platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants