Skip to content

fix(v1): aggregate multi-phase cleaning records - #1058

Merged
allenporter merged 1 commit into
Python-roborock:mainfrom
hCoureau:submit/fix/multiphase-clean-record-totals
Nov 22, 2026
Merged

allenporter merged 1 commit into
Python-roborock:mainfrom
hCoureau:submit/fix/multiphase-clean-record-totals

Conversation

@hCoureau

Copy link
Copy Markdown
Contributor

Context

get_clean_record can return a list with one record per phase of a clean, for example vacuum then mop. CleanRecordConverter is meant to combine the phases into one CleanRecord. #1034 noted multi-phase aggregation as a separate existing issue; this addresses it.

Problem

The converter combined the phases by assigning to CleanRecord.begin_datetime, which is a read-only property. The resulting AttributeError was swallowed by a broad except, so callers got the last phase's duration, area, counters and start_type instead of totals for the whole clean.

Changes

  • Build the combined record with dataclasses.replace on the last phase. It keeps the first phase's begin and start_type and sums duration, area, avoid_count and wash_count across phases, which is what the existing code was trying to do.
  • A field that no phase reports stays None and is not filled in as 0.
  • Remove the broad except Exception. A reply that mixes structured and list-form phases now raises RoborockParsingException.

Testing

  • New tests: a three-phase record, including a counter reported by only one phase and one reported by none, and two mixed-format replies. All three cases fail without the fix.
  • 2,364 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), 20 single-phase records read through this branch parse to the same duration, area, begin and end as the raw replies, so the single-phase path is unchanged on hardware.
  • The multi-phase and mixed-format payloads are synthetic. Every record I have seen from this device has one phase, including vacuum-and-mop runs with mop washes.

@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 — ready to approve. No findings survived adversarial self-check, and all CI checks pass.

Architectural Review (Priority 1 → 3)

  • Priority 1 — Public Trait APIs & Consumer Contracts (roborock/devices/traits/v1/clean_summary.py): Cleanly typed pure helper _sum_reported(values: list[int | None]) -> int | None and dataclasses.replace(records[-1], ...) preserve the CleanRecord dataclass contract without mutating intermediate records or assigning to read-only @property attributes (begin_datetime, square_meter_area), which now recompute automatically from begin and area. Unreported fields stay None instead of being coerced to 0.
  • Priority 2 — Data Lifecycle & State Management: Removes the broad except Exception (# noqa: BLE001) that silently swallowed the AttributeError on begin_datetime, aligning with AGENTS.md §4 (Specific Exception Narrowing). Mixed dict/non-dict phase lists now raise ValueError("Mixed clean record formats"), which CleanSummaryTrait.get_clean_record wraps in RoborockParsingException.
  • Priority 3 — Wire Protocols, Codecs & Tests (tests/devices/traits/v1/test_clean_summary.py): Single-dict, wrapped single-dict ([{...}]), legacy flat/nested list, and empty-list paths remain unchanged. Colocated tests cover 3-phase aggregation (including partially reported and unreported counters) and parametrized mixed-format rejection (dict-first / dict-last).

RR_API Cross-Verification

  • Checked com.roborock.tanos (hermes/.../module_2328.js, nonhermes/.../2497.js, 2470.js, 2573.js) and Qrevo 2 Pro Series (module_2363.js): the official Roborock app only reads result[0] from get_clean_record (either as a structured dict when isNewDataForCleanHistoryDetail() is true or a 9-element list otherwise) and does not implement client-side multi-phase aggregation.
  • Multi-dict aggregation in python-roborock originated in #206 (07ce71a) for firmware returning multiple phase dicts in a single get_clean_record reply, and silently broke when begin_datetime / square_meter_area were later converted from dataclass fields to read-only @property methods. This PR faithfully restores the intended aggregation semantics without altering single-phase behavior.

@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
Combining a multi-phase clean record assigned to the read-only
begin_datetime property. The error was swallowed, so callers got the
last phase's duration, area and counters and its start type. Build the
record from the last phase with the first phase's begin and start type,
and sum duration, area and counters across phases; fields no phase
reports stay unset. Replies mixing record formats now raise a parsing
error.
@hCoureau
hCoureau force-pushed the submit/fix/multiphase-clean-record-totals branch from ca23e47 to c3ccfc4 Compare November 21, 2026 21:36
@allenporter
allenporter merged commit 4f8ca86 into Python-roborock:main Nov 22, 2026
9 checks passed
@hCoureau
hCoureau deleted the submit/fix/multiphase-clean-record-totals 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