Restore state_class to derivative sensor#163557
Conversation
|
Hey there @afaucogney, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR restores the state_class = MEASUREMENT attribute to the derivative sensor, which was previously removed in PR #88952 due to state restoration issues. The underlying problems that caused the revert have been fixed in related PRs #147468 (handling unavailability) and #91071 (using RestoreSensor for proper state restoration). This change enables statistics collection for derivative sensors.
Changes:
- Add
_attr_state_class = SensorStateClass.MEASUREMENTto the DerivativeSensor class - Add test assertion to verify state_class attribute is present in sensor states
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| homeassistant/components/derivative/sensor.py | Adds _attr_state_class = SensorStateClass.MEASUREMENT class attribute to enable statistics for derivative sensor |
| tests/components/derivative/test_sensor.py | Adds assertion in setup_tests helper to verify state_class attribute is set correctly |
justanotherariel
left a comment
There was a problem hiding this comment.
Looks good to me. CC @emontnemery as you reverted this change previously - do you see any other reason that blocks this?
|
@emontnemery / @justanotherariel Can we proceed with this or is there anything @karwosts and/or I can do? |
Proposed change
Restore statistics to derivative sensors.
Was previously removed in #88952
Previous issues:
Derivative now restores native_value and unit, as well as correctly handles unavailable during times when source is unavailable.
Related PRs:
#147468
#91071
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: