Skip to content

fix(v1): serialize the last clean record of the clean summary - #1059

Merged
allenporter merged 2 commits into
Python-roborock:mainfrom
hCoureau:submit/fix/clean-summary-detail-dataclass
Nov 22, 2026
Merged

allenporter merged 2 commits into
Python-roborock:mainfrom
hCoureau:submit/fix/clean-summary-detail-dataclass

Conversation

@hCoureau

Copy link
Copy Markdown
Contributor

Context

CleanSummaryTrait fetches the clean summary and then the most recent clean record, and exposes the record as last_clean_record on CleanSummaryWithDetail.

Problem

CleanSummaryWithDetail declares last_clean_record but is not a dataclass, so the attribute is not a dataclass field:

  • as_dict() and device diagnostics drop the fetched record.
  • from_dict() ignores it.
  • CleanSummaryWithDetail(last_clean_record=...) raises TypeError.

Changes

  • Make CleanSummaryWithDetail a @dataclass(repr=False), keeping the shared attribute repr.
  • CleanSummaryConverter now returns plain CleanSummary objects. merge_trait_values copies every field of the converted object, so otherwise each summary refresh would reset the new field to None and a failed record fetch would lose the previous record.
  • Diagnostics now include lastCleanRecord; the snapshot is updated.

Testing

  • New test for the as_dict()/from_dict() round trip of CleanSummaryWithDetail. It fails on main, as does the updated snapshot.
  • New test that the previous record is kept when the record fetch fails. It fails if the converter change is reverted.
  • 2,363 tests passed on each of Python 3.11 and 3.14, on current main.
  • pre-commit, commitlint and source/wheel builds passed.

Evidence

  • On a Qrevo 2 Pro (roborock.vacuum.a294, firmware 02.40.54) with this change: as_dict() includes lastCleanRecord, from_dict(as_dict()) keeps the record, a second summary refresh keeps the same record, and the record key is present in diagnostics.
  • Keeping the previous record when the record fetch fails uses a simulated failure only.

CleanSummaryWithDetail declared last_clean_record without being a
dataclass, so as_dict() and device diagnostics dropped the fetched
record, from_dict() ignored it and the constructor rejected it.
Make the class a dataclass. The clean summary converter now returns
plain CleanSummary objects, so a summary refresh only updates the
summary fields and a failed record fetch keeps the previous record.
@Lash-L Lash-L added Small PR Small pull request (<200 lines) bug Something isn't working V1 V1 platform labels Nov 18, 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

Clean, tightly scoped bugfix (a865d54) with all CI checks passing. No blocking issues or defects survived adversarial self-check — this PR is clean and ready to approve.

Layer-by-Layer Assessment

  • Priority 1 — Public Trait APIs & Consumer Contracts (roborock/data/v1/v1_containers.py, roborock/devices/traits/v1/clean_summary.py):
    • Adding @dataclass(repr=False) to CleanSummaryWithDetail promotes last_clean_record: CleanRecord | None = None into a proper RoborockBase dataclass field, fixing as_dict() / diagnostics serialization (lastCleanRecord), from_dict() recursive deserialization, keyword construction, and __eq__ comparison while preserving CleanSummary.__repr__ (_attr_repr).
    • lastCleanRecord contains only cleaning metrics/timestamps (no sensitive user or transport data) and is safe in device.diagnostic_data().
  • Priority 2 — Data Lifecycle & State Management (roborock/devices/traits/v1/clean_summary.py):
    • Updating CleanSummaryConverter.convert() to return CleanSummary prevents merge_trait_values() during super().refresh() from overwriting self.last_clean_record with None before get_clean_record() runs.
    • Verified all refresh paths: successful refresh updates last_clean_record; failed GET_CLEAN_RECORD retains the previous last_clean_record (matching main); empty/missing records still explicitly resets self.last_clean_record = None.
  • Priority 3 — Wire Protocols, Codecs & Resilient Enums:
    • No wire protocol or enum changes; CleanRecord enum fields round-trip cleanly through as_dict() / from_dict().
  • Tests & Fixtures (tests/data/v1/test_v1_containers.py, tests/devices/traits/v1/test_clean_summary.py, tests/devices/__snapshots__/test_v1_device.ambr):
    • Tests are properly colocated in their mirror suites, assert on public API behavior (as_dict()/from_dict() round-trip and retention on GET_CLEAN_RECORD failure), and update the diagnostics snapshot accurately.

@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 merged commit bf5b6f2 into Python-roborock:main Nov 22, 2026
9 checks passed
@hCoureau
hCoureau deleted the submit/fix/clean-summary-detail-dataclass branch November 22, 2026 13:04
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 Small PR Small pull request (<200 lines) V1 V1 platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants