Optimize fetching statistics by avoiding timestamp conversions (#87845)

* Optimize fetching statistics by avoiding timestamp conversions

* remove accidential unrelated change

* fix test

* recreate so we handle timezone changes
This commit is contained in:
J. Nick Koston 2023-02-10 10:26:46 -06:00 committed by GitHub
parent 6a1cd75a67
commit c35661947a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 346 additions and 321 deletions

View file

@ -162,8 +162,8 @@ def test_compile_hourly_statistics(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -236,8 +236,8 @@ def test_compile_hourly_statistics_purged_state_changes(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -345,8 +345,8 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(13.050847),
"min": pytest.approx(-10.0),
"max": pytest.approx(30.0),
@ -357,8 +357,8 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
],
"sensor.test2": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": 13.05084745762712,
"min": -10.0,
"max": 30.0,
@ -369,8 +369,8 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
],
"sensor.test3": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": 13.05084745762712,
"min": -10.0,
"max": 30.0,
@ -381,8 +381,8 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
],
"sensor.test6": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(13.050847),
"min": pytest.approx(-10.0),
"max": pytest.approx(30.0),
@ -393,8 +393,8 @@ def test_compile_hourly_statistics_wrong_unit(hass_recorder, caplog, attributes)
],
"sensor.test7": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(13.050847),
"min": pytest.approx(-10.0),
"max": pytest.approx(30.0),
@ -503,32 +503,32 @@ async def test_compile_hourly_sum_statistics_amount(
expected_stats = {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(period0),
"last_reset": process_timestamp(period0).timestamp(),
"state": pytest.approx(factor * seq[2]),
"sum": pytest.approx(factor * 10.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(factor * seq[5]),
"sum": pytest.approx(factor * 40.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(factor * seq[8]),
"sum": pytest.approx(factor * 70.0),
},
@ -695,22 +695,22 @@ def test_compile_hourly_sum_statistics_amount_reset_every_state_change(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(dt_util.as_local(one)),
"last_reset": process_timestamp(dt_util.as_local(one)).timestamp(),
"state": pytest.approx(factor * seq[7]),
"sum": pytest.approx(factor * (sum(seq) - seq[0])),
},
{
"start": process_timestamp(zero + timedelta(minutes=5)),
"end": process_timestamp(zero + timedelta(minutes=10)),
"start": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(dt_util.as_local(two)),
"last_reset": process_timestamp(dt_util.as_local(two)).timestamp(),
"state": pytest.approx(factor * seq[7]),
"sum": pytest.approx(factor * (2 * sum(seq) - seq[0])),
},
@ -794,12 +794,12 @@ def test_compile_hourly_sum_statistics_amount_invalid_last_reset(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(dt_util.as_local(one)),
"last_reset": process_timestamp(dt_util.as_local(one)).timestamp(),
"state": pytest.approx(factor * seq[7]),
"sum": pytest.approx(factor * (sum(seq) - seq[0] - seq[3])),
},
@ -880,12 +880,12 @@ def test_compile_hourly_sum_statistics_nan_inf_state(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(one),
"last_reset": process_timestamp(one).timestamp(),
"state": pytest.approx(factor * seq[7]),
"sum": pytest.approx(
factor * (seq[2] + seq[3] + seq[4] + seq[6] + seq[7])
@ -1008,8 +1008,8 @@ def test_compile_hourly_sum_statistics_negative_state(
stats = statistics_during_period(hass, zero, period="5minute")
assert stats[entity_id] == [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1099,8 +1099,8 @@ def test_compile_hourly_sum_statistics_total_no_reset(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1109,8 +1109,8 @@ def test_compile_hourly_sum_statistics_total_no_reset(
"sum": pytest.approx(factor * 10.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1119,8 +1119,8 @@ def test_compile_hourly_sum_statistics_total_no_reset(
"sum": pytest.approx(factor * 30.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1201,8 +1201,8 @@ def test_compile_hourly_sum_statistics_total_increasing(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1211,8 +1211,8 @@ def test_compile_hourly_sum_statistics_total_increasing(
"sum": pytest.approx(factor * 10.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1221,8 +1221,8 @@ def test_compile_hourly_sum_statistics_total_increasing(
"sum": pytest.approx(factor * 50.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1315,8 +1315,8 @@ def test_compile_hourly_sum_statistics_total_increasing_small_dip(
"sensor.test1": [
{
"last_reset": None,
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1325,8 +1325,8 @@ def test_compile_hourly_sum_statistics_total_increasing_small_dip(
},
{
"last_reset": None,
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1335,8 +1335,8 @@ def test_compile_hourly_sum_statistics_total_increasing_small_dip(
},
{
"last_reset": None,
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
@ -1408,32 +1408,32 @@ def test_compile_hourly_energy_statistics_unsupported(hass_recorder, caplog):
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(period0),
"last_reset": process_timestamp(period0).timestamp(),
"state": pytest.approx(20.0),
"sum": pytest.approx(10.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(40.0),
"sum": pytest.approx(40.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(70.0),
"sum": pytest.approx(70.0),
},
@ -1520,96 +1520,96 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(period0),
"last_reset": process_timestamp(period0).timestamp(),
"state": pytest.approx(20.0),
"sum": pytest.approx(10.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(40.0),
"sum": pytest.approx(40.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(70.0),
"sum": pytest.approx(70.0),
},
],
"sensor.test2": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(period0),
"last_reset": process_timestamp(period0).timestamp(),
"state": pytest.approx(130.0),
"sum": pytest.approx(20.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(45.0),
"sum": pytest.approx(-65.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(75.0),
"sum": pytest.approx(-35.0),
},
],
"sensor.test3": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(period0),
"last_reset": process_timestamp(period0).timestamp(),
"state": pytest.approx(5.0),
"sum": pytest.approx(5.0),
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(50.0),
"sum": pytest.approx(60.0),
},
{
"start": process_timestamp(period2),
"end": process_timestamp(period2_end),
"start": process_timestamp(period2).timestamp(),
"end": process_timestamp(period2_end).timestamp(),
"max": None,
"mean": None,
"min": None,
"last_reset": process_timestamp(four),
"last_reset": process_timestamp(four).timestamp(),
"state": pytest.approx(90.0),
"sum": pytest.approx(100.0),
},
@ -1665,8 +1665,8 @@ def test_compile_hourly_statistics_unchanged(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(four),
"end": process_timestamp(four + timedelta(minutes=5)),
"start": process_timestamp(four).timestamp(),
"end": process_timestamp(four + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(value),
"min": pytest.approx(value),
"max": pytest.approx(value),
@ -1697,8 +1697,8 @@ def test_compile_hourly_statistics_partially_unavailable(hass_recorder, caplog):
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(21.1864406779661),
"min": pytest.approx(10.0),
"max": pytest.approx(25.0),
@ -1766,8 +1766,8 @@ def test_compile_hourly_statistics_unavailable(
assert stats == {
"sensor.test2": [
{
"start": process_timestamp(four),
"end": process_timestamp(four + timedelta(minutes=5)),
"start": process_timestamp(four).timestamp(),
"end": process_timestamp(four + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(value),
"min": pytest.approx(value),
"max": pytest.approx(value),
@ -1988,8 +1988,8 @@ def test_compile_hourly_statistics_changing_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2023,8 +2023,8 @@ def test_compile_hourly_statistics_changing_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2166,8 +2166,8 @@ def test_compile_hourly_statistics_changing_units_3(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2201,8 +2201,8 @@ def test_compile_hourly_statistics_changing_units_3(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2274,8 +2274,8 @@ def test_compile_hourly_statistics_convert_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2317,8 +2317,8 @@ def test_compile_hourly_statistics_convert_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean * factor),
"min": pytest.approx(min * factor),
"max": pytest.approx(max * factor),
@ -2327,8 +2327,8 @@ def test_compile_hourly_statistics_convert_units_1(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=10)),
"end": process_timestamp(zero + timedelta(minutes=15)),
"start": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=15)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2406,8 +2406,8 @@ def test_compile_hourly_statistics_equivalent_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2437,8 +2437,8 @@ def test_compile_hourly_statistics_equivalent_units_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2447,8 +2447,8 @@ def test_compile_hourly_statistics_equivalent_units_1(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=10)),
"end": process_timestamp(zero + timedelta(minutes=15)),
"start": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=15)).timestamp(),
"mean": pytest.approx(mean2),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2521,8 +2521,10 @@ def test_compile_hourly_statistics_equivalent_units_2(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero + timedelta(seconds=30 * 5)),
"end": process_timestamp(zero + timedelta(seconds=30 * 15)),
"start": process_timestamp(
zero + timedelta(seconds=30 * 5)
).timestamp(),
"end": process_timestamp(zero + timedelta(seconds=30 * 15)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2590,8 +2592,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean1),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2635,8 +2637,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean1),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2645,8 +2647,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=10)),
"end": process_timestamp(zero + timedelta(minutes=15)),
"start": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=15)).timestamp(),
"mean": pytest.approx(mean2),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2690,8 +2692,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean1),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2700,8 +2702,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=10)),
"end": process_timestamp(zero + timedelta(minutes=15)),
"start": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=15)).timestamp(),
"mean": pytest.approx(mean2),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2710,8 +2712,8 @@ def test_compile_hourly_statistics_changing_device_class_1(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=20)),
"end": process_timestamp(zero + timedelta(minutes=25)),
"start": process_timestamp(zero + timedelta(minutes=20)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=25)).timestamp(),
"mean": pytest.approx(mean2),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2780,8 +2782,8 @@ def test_compile_hourly_statistics_changing_device_class_2(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2825,8 +2827,8 @@ def test_compile_hourly_statistics_changing_device_class_2(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(zero),
"end": process_timestamp(zero + timedelta(minutes=5)),
"start": process_timestamp(zero).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=5)).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2835,8 +2837,8 @@ def test_compile_hourly_statistics_changing_device_class_2(
"sum": None,
},
{
"start": process_timestamp(zero + timedelta(minutes=10)),
"end": process_timestamp(zero + timedelta(minutes=15)),
"start": process_timestamp(zero + timedelta(minutes=10)).timestamp(),
"end": process_timestamp(zero + timedelta(minutes=15)).timestamp(),
"mean": pytest.approx(mean2),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2954,8 +2956,8 @@ def test_compile_hourly_statistics_changing_state_class(
assert stats == {
"sensor.test1": [
{
"start": process_timestamp(period0),
"end": process_timestamp(period0_end),
"start": process_timestamp(period0).timestamp(),
"end": process_timestamp(period0_end).timestamp(),
"mean": pytest.approx(mean),
"min": pytest.approx(min),
"max": pytest.approx(max),
@ -2964,8 +2966,8 @@ def test_compile_hourly_statistics_changing_state_class(
"sum": None,
},
{
"start": process_timestamp(period1),
"end": process_timestamp(period1_end),
"start": process_timestamp(period1).timestamp(),
"end": process_timestamp(period1_end).timestamp(),
"mean": None,
"min": None,
"max": None,
@ -3204,8 +3206,8 @@ def test_compile_statistics_hourly_daily_monthly_summary(hass_recorder, caplog):
)
expected_stats[entity_id].append(
{
"start": process_timestamp(start),
"end": process_timestamp(end),
"start": process_timestamp(start).timestamp(),
"end": process_timestamp(end).timestamp(),
"mean": pytest.approx(expected_average),
"min": pytest.approx(expected_minimum),
"max": pytest.approx(expected_maximum),
@ -3261,8 +3263,8 @@ def test_compile_statistics_hourly_daily_monthly_summary(hass_recorder, caplog):
)
expected_stats[entity_id].append(
{
"start": process_timestamp(start),
"end": process_timestamp(end),
"start": process_timestamp(start).timestamp(),
"end": process_timestamp(end).timestamp(),
"mean": pytest.approx(expected_average),
"min": pytest.approx(expected_minimum),
"max": pytest.approx(expected_maximum),
@ -3318,8 +3320,8 @@ def test_compile_statistics_hourly_daily_monthly_summary(hass_recorder, caplog):
)
expected_stats[entity_id].append(
{
"start": process_timestamp(start),
"end": process_timestamp(end),
"start": process_timestamp(start).timestamp(),
"end": process_timestamp(end).timestamp(),
"mean": pytest.approx(expected_average),
"min": pytest.approx(expected_minimum),
"max": pytest.approx(expected_maximum),
@ -3375,8 +3377,8 @@ def test_compile_statistics_hourly_daily_monthly_summary(hass_recorder, caplog):
)
expected_stats[entity_id].append(
{
"start": process_timestamp(start),
"end": process_timestamp(end),
"start": process_timestamp(start).timestamp(),
"end": process_timestamp(end).timestamp(),
"mean": pytest.approx(expected_average),
"min": pytest.approx(expected_minimum),
"max": pytest.approx(expected_maximum),