Allow small dip in total_increasing sensor without detecting a reset (#55153)

This commit is contained in:
Erik Montnemery 2021-08-24 17:23:55 +02:00 committed by GitHub
parent 8877f37da0
commit fa9f91325c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 91 additions and 3 deletions

View file

@ -226,6 +226,11 @@ def _normalize_states(
return DEVICE_CLASS_UNITS[key], fstates
def reset_detected(state: float, previous_state: float | None) -> bool:
"""Test if a total_increasing sensor has been reset."""
return previous_state is not None and state < 0.9 * previous_state
def compile_statistics(
hass: HomeAssistant, start: datetime.datetime, end: datetime.datetime
) -> dict:
@ -308,7 +313,7 @@ def compile_statistics(
fstate,
)
elif state_class == STATE_CLASS_TOTAL_INCREASING and (
old_state is None or (new_state is not None and fstate < new_state)
old_state is None or reset_detected(fstate, new_state)
):
reset = True
_LOGGER.info(