forked from home-assistant/core
Improve log for sum statistics (#55502)
This commit is contained in:
committed by
Paulus Schoutsen
parent
4045eee2e5
commit
d4aadd8af0
@@ -406,6 +406,19 @@ def compile_statistics( # noqa: C901
|
|||||||
and (last_reset := state.attributes.get("last_reset"))
|
and (last_reset := state.attributes.get("last_reset"))
|
||||||
!= old_last_reset
|
!= old_last_reset
|
||||||
):
|
):
|
||||||
|
if old_state is None:
|
||||||
|
_LOGGER.info(
|
||||||
|
"Compiling initial sum statistics for %s, zero point set to %s",
|
||||||
|
entity_id,
|
||||||
|
fstate,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
_LOGGER.info(
|
||||||
|
"Detected new cycle for %s, last_reset set to %s (old last_reset %s)",
|
||||||
|
entity_id,
|
||||||
|
last_reset,
|
||||||
|
old_last_reset,
|
||||||
|
)
|
||||||
reset = True
|
reset = True
|
||||||
elif old_state is None and last_reset is None:
|
elif old_state is None and last_reset is None:
|
||||||
reset = True
|
reset = True
|
||||||
@@ -420,7 +433,7 @@ def compile_statistics( # noqa: C901
|
|||||||
):
|
):
|
||||||
reset = True
|
reset = True
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"Detected new cycle for %s, zero point set to %s (old zero point %s)",
|
"Detected new cycle for %s, value dropped from %s to %s",
|
||||||
entity_id,
|
entity_id,
|
||||||
fstate,
|
fstate,
|
||||||
new_state,
|
new_state,
|
||||||
|
@@ -273,6 +273,9 @@ def test_compile_hourly_sum_statistics_amount(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert "Error while processing event StatisticsTask" not in caplog.text
|
assert "Error while processing event StatisticsTask" not in caplog.text
|
||||||
|
assert "Detected new cycle for sensor.test1, last_reset set to" in caplog.text
|
||||||
|
assert "Compiling initial sum statistics for sensor.test1" in caplog.text
|
||||||
|
assert "Detected new cycle for sensor.test1, value dropped" not in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("state_class", ["measurement"])
|
@pytest.mark.parametrize("state_class", ["measurement"])
|
||||||
@@ -424,6 +427,9 @@ def test_compile_hourly_sum_statistics_total_increasing(
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
assert "Error while processing event StatisticsTask" not in caplog.text
|
assert "Error while processing event StatisticsTask" not in caplog.text
|
||||||
|
assert "Detected new cycle for sensor.test1, last_reset set to" not in caplog.text
|
||||||
|
assert "Compiling initial sum statistics for sensor.test1" in caplog.text
|
||||||
|
assert "Detected new cycle for sensor.test1, value dropped" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Reference in New Issue
Block a user