Skip to content

fix(v1): convert V1 consumable DPS remaining-life percentages to work… - #1099

Open
kirintwn wants to merge 1 commit into
Python-roborock:mainfrom
klh-homes:fix/saros-z70-consumable-life
Open

kirintwn wants to merge 1 commit into
Python-roborock:mainfrom
klh-homes:fix/saros-z70-consumable-life

Conversation

@kirintwn

@kirintwn kirintwn commented Dec 3, 2026

Copy link
Copy Markdown

Fixes #1098

Problem

V1 Roborock devices report consumable wear in two different units:

  • get_consumable RPC returns cumulative elapsed work time in seconds (main_brush_work_time, side_brush_work_time, filter_work_time), which Consumable.*_time_left subtracts from MAIN_BRUSH_REPLACE_TIME (300 h), SIDE_BRUSH_REPLACE_TIME (200 h), and FILTER_REPLACE_TIME (150 h).
  • Unsolicited MQTT DPS push updates 125 (main_brush_life), 126 (side_brush_life), and 127 (filter_life) report remaining life percentage (0–100), as defined in V1 product schemas across supported V1 models (device_info.yaml and tests/testdata/).

Previously, ConsumableTrait.update_from_dps() passed DPS 125–127 directly through DpsDataConverter.update_from_dps(), overwriting main_brush_work_time, side_brush_work_time, and filter_work_time with the 0–100 remaining-life percentages. On a Saros Z70 (roborock.vacuum.a179), pushing 125: 34 replaced 717,768 s (~101 h left) with 34 s (~300 h left) until the next get_consumable poll restored it.

Changes

  • roborock/devices/traits/v1/consumeable.py:
    • Convert pushed V1 DPS 125–127 remaining-life percentages (0–100, integer or numeric string) to elapsed work time in seconds (((100 - life_percent) * replace_time) // 100) via pure helper functions before passing the update to _DPS_CONVERTER.
    • Estimate the current remaining-life bucket with max(0, min(100, 100 - (work_time * 100) // replace_time)), using the rounding observed on Saros Z70 firmware 02.64.56 (717,768 s → 34%, 258,513 s → 65%, 138,327 s → 75%).
    • Keep exact polled seconds and suppress spurious listener notifications when the pushed percentage matches the current wear bucket or reports a higher life percentage below 100% (preventing a delayed MQTT push from rolling back a newer local RPC get_consumable poll, and preserving overdue consumables at 0% with negative *_time_left).
    • Still update *_work_time and notify listeners on initial pushes before refresh() and when wear crosses into a lower percentage. A 100% push resets cached work time once prior wear reaches 1%. Within the 100% bucket, the trait preserves exact polled seconds.
    • Drop out-of-range (< 0 or > 100) or malformed values with debug logging while still applying valid sibling fields in the same push.
  • roborock/roborock_message.py:
    • Document the wire units (0–100 remaining life percentage) in inline comments on RoborockDataProtocol 125–127 while keeping existing enum names and Consumable dps field metadata intact for DeviceFeaturesTrait.is_field_supported and backwards compatibility.
  • tests/devices/traits/v1/test_consumable.py:
    • Add regression tests covering the Saros Z70 readings (both via refresh() + push and standalone ConsumableTrait()), unset percentage conversion, 1% wear drops, delayed stale pushes below 100%, external 100% resets, reset_consumable() + 100% push, small polled runtime under 1% wear, overdue 0% preservation and reset, numeric strings, invalid/out-of-range values, and unrelated DPS protocols.

Other protocol families (B01 Q7, B01 Q10, A01 Dyad/Zeo, Mower) and ConsumableTrait.refresh() / reset_consumable() behavior are unaffected.

Verification

Verified locally (Python 3.14.10):

  • Baseline reproduction: verified against v7.38.0 that pushing DPS 125: 34 overwrote main_brush_work_time from 717768 to 34 (and from 723600 to 34), and added regression coverage for both the unit conversion and the stale-push guard.
  • uv run pytest tests/devices/traits/v1/test_consumable.py --cov=roborock.devices.traits.v1.consumeable --cov-branch --cov-report=term-missing — 35 passed (100% statement and branch coverage across all new/modified lines).
  • uv run pre-commit run --all-files — all hooks passed (ruff, ruff-format, mypy, codespell, and standard pre-commit checks).
  • uv run pytest -n auto — 3322 passed, 45 xfailed.
  • uv build — sdist and wheel built cleanly.

… time

V1 devices push remaining consumable life percentages (0-100) on DPS 125, 126, and 127 (main_brush_life, side_brush_life, filter_life), whereas get_consumable returns cumulative elapsed work time in seconds.

Previously ConsumableTrait.update_from_dps wrote those 0-100 values directly into main_brush_work_time, side_brush_work_time, and filter_work_time, causing remaining-time calculations to jump to nearly full lifetime until the next get_consumable poll.

Convert pushed DPS 125-127 percentages into elapsed work time in seconds using each consumable's replacement interval. Keep cached polled seconds when the pushed percentage matches the current wear bucket or reports higher life below 100% (such as a delayed MQTT push arriving after a newer local RPC poll, overdue consumables at 0%, or recently reset consumables under 1% wear), while still reflecting initial pushes before refresh, percentage drops, and external 100% resets once worn. Ignore out-of-range or malformed values.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Saros Z70 brush and filter life percentages are treated as elapsed seconds

2 participants