Add support for total and total_increasing sensor state classes#54523
Add support for total and total_increasing sensor state classes#54523emontnemery merged 8 commits intohome-assistant:devfrom
Conversation
| elif old_state is None and last_reset is None: | ||
| reset = True | ||
| elif state_class == STATE_CLASS_TOTAL_INCREASING and ( | ||
| old_state is None or fstate < old_state |
There was a problem hiding this comment.
Might be worth usings omething like fstate < 0.9 * old_state? I'm just thinking of cases where a slightly noisy energy sensor is being used in an integration to calculate power. If the sensor is measuring 0 +/- some noise it is possible for the value to creep down a small amount without being a true reset
There was a problem hiding this comment.
I think that needs to be handled by the integration if it claims STATE_CLASS_TOTAL_INCREASING.
In the example with integrating a noisy power sensor (I think that's what you meant?) it could perhaps be handled by ignoring negative power?
There was a problem hiding this comment.
Agreed. I think it's best that the integration claiming that the sensor will only increase ensures that is true. I thought of some others where a less than could be an issue but in all cases the integration should know what it's doing better
| """Return state attributes.""" | ||
| if last_reset := self.last_reset: | ||
| if ( | ||
| last_reset is not None |
There was a problem hiding this comment.
This is not needed, L162 will not continue if this is None
|
Removed the breaking change label, as it never went to stable. |
Breaking change
Although not a breaking change from a user's perspective, this is a significant change from a developer's perspective.
It should be noted that the state class
totalwas removed.Details here: home-assistant/developers.home-assistant#1028
Proposed change
Add support for
totalandtotal_increasingsensor state classes:If the sensor's state class is
STATE_CLASS_TOTAL, the last_reset attribute can optionally be set to indicate a new meter cycle.If the sensor's state class is
STATE_CLASS_TOTAL_INCREASING, a decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter. The last_reset attribute will be ignored when compiling statistics. This state class is useful for gas meters, electricity meters, water meters etc.Type of change
Additional information
Checklist
black --fast 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..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: