Fix history_stats test failing during DST (#89589)
Note that there is one test that needs `now()` as it is timezone aware
This commit is contained in:
parent
0575b9bc88
commit
4dcf7c6267
1 changed files with 56 additions and 56 deletions
|
@ -30,7 +30,7 @@ async def test_setup(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"platform": "history_stats",
|
||||
"entity_id": "binary_sensor.test_id",
|
||||
"state": "on",
|
||||
"start": "{{ now().replace(hour=0)"
|
||||
"start": "{{ utcnow().replace(hour=0)"
|
||||
".replace(minute=0).replace(second=0) }}",
|
||||
"duration": "02:00",
|
||||
"name": "Test",
|
||||
|
@ -54,7 +54,7 @@ async def test_setup_multiple_states(
|
|||
"platform": "history_stats",
|
||||
"entity_id": "binary_sensor.test_id",
|
||||
"state": ["on", "true"],
|
||||
"start": "{{ now().replace(hour=0)"
|
||||
"start": "{{ utcnow().replace(hour=0)"
|
||||
".replace(minute=0).replace(second=0) }}",
|
||||
"duration": "02:00",
|
||||
"name": "Test",
|
||||
|
@ -76,7 +76,7 @@ async def test_setup_multiple_states(
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "Test",
|
||||
"state": "on",
|
||||
"start": "{{ now() }}",
|
||||
"start": "{{ utcnow() }}",
|
||||
"duration": "TEST",
|
||||
},
|
||||
{
|
||||
|
@ -84,15 +84,15 @@ async def test_setup_multiple_states(
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "Test",
|
||||
"state": "on",
|
||||
"start": "{{ now() }}",
|
||||
"start": "{{ utcnow() }}",
|
||||
},
|
||||
{
|
||||
"platform": "history_stats",
|
||||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "Test",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"duration": "01:00",
|
||||
},
|
||||
],
|
||||
|
@ -226,7 +226,7 @@ async def test_reload(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "test",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"duration": "01:00",
|
||||
},
|
||||
},
|
||||
|
@ -292,8 +292,8 @@ async def test_measure_multiple(recorder_mock: Recorder, hass: HomeAssistant) ->
|
|||
"entity_id": "input_select.test_id",
|
||||
"name": "sensor1",
|
||||
"state": ["orange", "blue"],
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -301,8 +301,8 @@ async def test_measure_multiple(recorder_mock: Recorder, hass: HomeAssistant) ->
|
|||
"entity_id": "unknown.test_id",
|
||||
"name": "sensor2",
|
||||
"state": ["orange", "blue"],
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -310,8 +310,8 @@ async def test_measure_multiple(recorder_mock: Recorder, hass: HomeAssistant) ->
|
|||
"entity_id": "input_select.test_id",
|
||||
"name": "sensor3",
|
||||
"state": ["orange", "blue"],
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -319,8 +319,8 @@ async def test_measure_multiple(recorder_mock: Recorder, hass: HomeAssistant) ->
|
|||
"entity_id": "input_select.test_id",
|
||||
"name": "sensor4",
|
||||
"state": ["orange", "blue"],
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -371,8 +371,8 @@ async def test_measure(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor1",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -380,8 +380,8 @@ async def test_measure(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor2",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -390,7 +390,7 @@ async def test_measure(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"name": "sensor3",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -398,8 +398,8 @@ async def test_measure(recorder_mock: Recorder, hass: HomeAssistant) -> None:
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor4",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -453,8 +453,8 @@ async def test_async_on_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor1",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -462,8 +462,8 @@ async def test_async_on_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor2",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -471,8 +471,8 @@ async def test_async_on_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor3",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -480,8 +480,8 @@ async def test_async_on_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor4",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -531,8 +531,8 @@ async def test_async_off_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor1",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -540,8 +540,8 @@ async def test_async_off_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor2",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -549,8 +549,8 @@ async def test_async_off_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor3",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -558,8 +558,8 @@ async def test_async_off_entire_period(
|
|||
"entity_id": "binary_sensor.test_on_id",
|
||||
"name": "on_sensor4",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -1228,7 +1228,7 @@ async def test_measure_from_end_going_backwards(
|
|||
"name": "sensor1",
|
||||
"state": "on",
|
||||
"duration": {"hours": 1},
|
||||
"end": "{{ now() }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -1237,7 +1237,7 @@ async def test_measure_from_end_going_backwards(
|
|||
"name": "sensor2",
|
||||
"state": "on",
|
||||
"duration": {"hours": 1},
|
||||
"end": "{{ now() }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -1246,7 +1246,7 @@ async def test_measure_from_end_going_backwards(
|
|||
"name": "sensor3",
|
||||
"state": "on",
|
||||
"duration": {"hours": 1},
|
||||
"end": "{{ now() }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -1255,7 +1255,7 @@ async def test_measure_from_end_going_backwards(
|
|||
"name": "sensor4",
|
||||
"state": "on",
|
||||
"duration": {"hours": 1},
|
||||
"end": "{{ now() }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -1320,8 +1320,8 @@ async def test_measure_cet(recorder_mock: Recorder, hass: HomeAssistant) -> None
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor1",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -1329,8 +1329,8 @@ async def test_measure_cet(recorder_mock: Recorder, hass: HomeAssistant) -> None
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor2",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -1338,8 +1338,8 @@ async def test_measure_cet(recorder_mock: Recorder, hass: HomeAssistant) -> None
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor3",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -1347,8 +1347,8 @@ async def test_measure_cet(recorder_mock: Recorder, hass: HomeAssistant) -> None
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "sensor4",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ now() }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ utcnow() }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
@ -1495,8 +1495,8 @@ async def test_device_classes(recorder_mock: Recorder, hass: HomeAssistant) -> N
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "time",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(now()) + 3600 }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(utcnow()) + 3600 }}",
|
||||
"type": "time",
|
||||
},
|
||||
{
|
||||
|
@ -1504,8 +1504,8 @@ async def test_device_classes(recorder_mock: Recorder, hass: HomeAssistant) -> N
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "count",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(now()) + 3600 }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(utcnow()) + 3600 }}",
|
||||
"type": "count",
|
||||
},
|
||||
{
|
||||
|
@ -1513,8 +1513,8 @@ async def test_device_classes(recorder_mock: Recorder, hass: HomeAssistant) -> N
|
|||
"entity_id": "binary_sensor.test_id",
|
||||
"name": "ratio",
|
||||
"state": "on",
|
||||
"start": "{{ as_timestamp(now()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(now()) + 3600 }}",
|
||||
"start": "{{ as_timestamp(utcnow()) - 3600 }}",
|
||||
"end": "{{ as_timestamp(utcnow()) + 3600 }}",
|
||||
"type": "ratio",
|
||||
},
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue