Use correct state_class for utility meters with device classes that don't support total_increasing#170962
Merged
Conversation
…on't support total_increasing Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
|
Hey there @dgomes, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes utility_meter sensor emitting a "state_class 'total_increasing' is impossible for device_class" warning when wrapping sources whose device class (e.g. monetary) does not allow total_increasing. The state_class property now consults DEVICE_CLASS_STATE_CLASSES and falls back to SensorStateClass.TOTAL when TOTAL_INCREASING is not permitted for the input sensor's device class.
Changes:
- Look up allowed state classes from
DEVICE_CLASS_STATE_CLASSESand returnTOTALwhenTOTAL_INCREASINGis not allowed for the source device class. - Add a test verifying that a
monetarysource results instate_class: totalon the utility meter.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/utility_meter/sensor.py | Update state_class property to pick TOTAL when source device class disallows TOTAL_INCREASING. |
| tests/components/utility_meter/test_sensor.py | New test asserting MONETARY source produces SensorStateClass.TOTAL. |
dgomes
approved these changes
May 17, 2026
Copilot AI
pushed a commit
to AlCalzone/homeassistant-core
that referenced
this pull request
May 17, 2026
…on't support total_increasing (home-assistant#170962) Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: AlCalzone <17641229+AlCalzone@users.noreply.github.com>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Breaking change
Proposed change
The utility meter sensor unconditionally uses
state_class: total_increasingfor non-net-consumption meters. This is invalid for device classes likemonetary, which only supportsstate_class: total. This causes a warning on every state update:The fix looks up
DEVICE_CLASS_STATE_CLASSESto check whether the input sensor's device class actually supportstotal_increasing. If it doesn't,totalis used instead. This works generically for any current or future device class constraint, not justmonetary.The existing
last_resethandling inextra_state_attributesalready supportstotalstate class correctly (it's the same code path used bynet_consumption), so no additional changes are needed for long-term statistics.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: