mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Make new cycles for sensor sum statistics start with 0 as zero-point (#55473)
This commit is contained in:
parent
88a08fdf57
commit
f9225bad5f
@ -403,11 +403,8 @@ def compile_statistics(
|
|||||||
# ..and update the starting point
|
# ..and update the starting point
|
||||||
new_state = fstate
|
new_state = fstate
|
||||||
old_last_reset = last_reset
|
old_last_reset = last_reset
|
||||||
# Force a new cycle for STATE_CLASS_TOTAL_INCREASING to start at 0
|
# Force a new cycle for an existing sensor to start at 0
|
||||||
if (
|
if old_state is not None:
|
||||||
state_class == STATE_CLASS_TOTAL_INCREASING
|
|
||||||
and old_state is not None
|
|
||||||
):
|
|
||||||
old_state = 0.0
|
old_state = 0.0
|
||||||
else:
|
else:
|
||||||
old_state = new_state
|
old_state = new_state
|
||||||
|
@ -258,7 +258,7 @@ def test_compile_hourly_sum_statistics_amount(
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(factor * seq[5]),
|
"state": approx(factor * seq[5]),
|
||||||
"sum": approx(factor * 10.0),
|
"sum": approx(factor * 40.0),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"statistic_id": "sensor.test1",
|
"statistic_id": "sensor.test1",
|
||||||
@ -268,7 +268,7 @@ def test_compile_hourly_sum_statistics_amount(
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(factor * seq[8]),
|
"state": approx(factor * seq[8]),
|
||||||
"sum": approx(factor * 40.0),
|
"sum": approx(factor * 70.0),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -512,7 +512,7 @@ def test_compile_hourly_energy_statistics_unsupported(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(40.0),
|
"state": approx(40.0),
|
||||||
"sum": approx(10.0),
|
"sum": approx(40.0),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"statistic_id": "sensor.test1",
|
"statistic_id": "sensor.test1",
|
||||||
@ -522,7 +522,7 @@ def test_compile_hourly_energy_statistics_unsupported(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(70.0),
|
"state": approx(70.0),
|
||||||
"sum": approx(40.0),
|
"sum": approx(70.0),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -595,7 +595,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(40.0),
|
"state": approx(40.0),
|
||||||
"sum": approx(10.0),
|
"sum": approx(40.0),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"statistic_id": "sensor.test1",
|
"statistic_id": "sensor.test1",
|
||||||
@ -605,7 +605,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(70.0),
|
"state": approx(70.0),
|
||||||
"sum": approx(40.0),
|
"sum": approx(70.0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"sensor.test2": [
|
"sensor.test2": [
|
||||||
@ -627,7 +627,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(45.0),
|
"state": approx(45.0),
|
||||||
"sum": approx(-95.0),
|
"sum": approx(-65.0),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"statistic_id": "sensor.test2",
|
"statistic_id": "sensor.test2",
|
||||||
@ -637,7 +637,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(75.0),
|
"state": approx(75.0),
|
||||||
"sum": approx(-65.0),
|
"sum": approx(-35.0),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
"sensor.test3": [
|
"sensor.test3": [
|
||||||
@ -659,7 +659,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(50.0 / 1000),
|
"state": approx(50.0 / 1000),
|
||||||
"sum": approx(30.0 / 1000),
|
"sum": approx(60.0 / 1000),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"statistic_id": "sensor.test3",
|
"statistic_id": "sensor.test3",
|
||||||
@ -669,7 +669,7 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
|
|||||||
"min": None,
|
"min": None,
|
||||||
"last_reset": process_timestamp_to_utc_isoformat(four),
|
"last_reset": process_timestamp_to_utc_isoformat(four),
|
||||||
"state": approx(90.0 / 1000),
|
"state": approx(90.0 / 1000),
|
||||||
"sum": approx(70.0 / 1000),
|
"sum": approx(100.0 / 1000),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user