Force STATE_CLASS_TOTAL_INCREASING to reset to 0 (#54751)

* Force STATE_CLASS_TOTAL_INCREASING to reset to 0

* Tweak

* Correct detection of new cycle

* Fix typing
This commit is contained in:
Erik Montnemery 2021-08-17 23:05:31 +02:00 committed by GitHub
parent 8eec949835
commit 3a78f1fce6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View file

@ -308,7 +308,7 @@ def compile_statistics(
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
old_state is None or (new_state is not None and fstate < new_state)
):
reset = True
@ -319,7 +319,11 @@ def compile_statistics(
# ..and update the starting point
new_state = fstate
old_last_reset = last_reset
old_state = new_state
# Force a new cycle for STATE_CLASS_TOTAL_INCREASING to start at 0
if state_class == STATE_CLASS_TOTAL_INCREASING and old_state:
old_state = 0
else:
old_state = new_state
else:
new_state = fstate