Repository navigation
Conversation
… 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1098
Problem
V1 Roborock devices report consumable wear in two different units:
get_consumableRPC returns cumulative elapsed work time in seconds (main_brush_work_time,side_brush_work_time,filter_work_time), whichConsumable.*_time_leftsubtracts fromMAIN_BRUSH_REPLACE_TIME(300 h),SIDE_BRUSH_REPLACE_TIME(200 h), andFILTER_REPLACE_TIME(150 h).125(main_brush_life),126(side_brush_life), and127(filter_life) report remaining life percentage (0–100), as defined in V1 product schemas across supported V1 models (device_info.yamlandtests/testdata/).Previously,
ConsumableTrait.update_from_dps()passed DPS 125–127 directly throughDpsDataConverter.update_from_dps(), overwritingmain_brush_work_time,side_brush_work_time, andfilter_work_timewith the0–100remaining-life percentages. On a Saros Z70 (roborock.vacuum.a179), pushing125: 34replaced717,768s (~101 h left) with34s (~300 h left) until the nextget_consumablepoll restored it.Changes
roborock/devices/traits/v1/consumeable.py: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.max(0, min(100, 100 - (work_time * 100) // replace_time)), using the rounding observed on Saros Z70 firmware02.64.56(717,768s →34%,258,513s →65%,138,327s →75%).100%(preventing a delayed MQTT push from rolling back a newer local RPCget_consumablepoll, and preserving overdue consumables at0%with negative*_time_left).*_work_timeand notify listeners on initial pushes beforerefresh()and when wear crosses into a lower percentage. A100%push resets cached work time once prior wear reaches1%. Within the100%bucket, the trait preserves exact polled seconds.< 0or> 100) or malformed values with debug logging while still applying valid sibling fields in the same push.roborock/roborock_message.py:0–100remaining life percentage) in inline comments onRoborockDataProtocol125–127 while keeping existing enum names andConsumabledpsfield metadata intact forDeviceFeaturesTrait.is_field_supportedand backwards compatibility.tests/devices/traits/v1/test_consumable.py:refresh()+ push and standaloneConsumableTrait()), unset percentage conversion, 1% wear drops, delayed stale pushes below100%, external100%resets,reset_consumable()+100%push, small polled runtime under 1% wear, overdue0%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):
v7.38.0that pushing DPS125: 34overwrotemain_brush_work_timefrom717768to34(and from723600to34), 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.