mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Remove parametrization in recorder websocket api tests (#78864)
Remove parametrization in websocket api tests
This commit is contained in:
parent
7e9be812ca
commit
df47fda2a0
@ -82,29 +82,14 @@ TEMPERATURE_SENSOR_F_ATTRIBUTES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
async def test_statistics_during_period(hass, hass_ws_client, recorder_mock):
|
||||||
"units, attributes, state, value",
|
|
||||||
[
|
|
||||||
(IMPERIAL_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, 10, 10),
|
|
||||||
(METRIC_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, 10, 10),
|
|
||||||
(IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, 10, 10),
|
|
||||||
(METRIC_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, 10, 10),
|
|
||||||
(IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_F_ATTRIBUTES, 10, 10),
|
|
||||||
(METRIC_SYSTEM, TEMPERATURE_SENSOR_F_ATTRIBUTES, 10, 10),
|
|
||||||
(IMPERIAL_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, 1000, 1000),
|
|
||||||
(METRIC_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, 1000, 1000),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_statistics_during_period(
|
|
||||||
hass, hass_ws_client, recorder_mock, units, attributes, state, value
|
|
||||||
):
|
|
||||||
"""Test statistics_during_period."""
|
"""Test statistics_during_period."""
|
||||||
now = dt_util.utcnow()
|
now = dt_util.utcnow()
|
||||||
|
|
||||||
hass.config.units = units
|
hass.config.units = IMPERIAL_SYSTEM
|
||||||
await async_setup_component(hass, "sensor", {})
|
await async_setup_component(hass, "sensor", {})
|
||||||
await async_recorder_block_till_done(hass)
|
await async_recorder_block_till_done(hass)
|
||||||
hass.states.async_set("sensor.test", state, attributes=attributes)
|
hass.states.async_set("sensor.test", 10, attributes=POWER_SENSOR_KW_ATTRIBUTES)
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
do_adhoc_statistics(hass, start=now)
|
do_adhoc_statistics(hass, start=now)
|
||||||
@ -142,9 +127,9 @@ async def test_statistics_during_period(
|
|||||||
"statistic_id": "sensor.test",
|
"statistic_id": "sensor.test",
|
||||||
"start": now.isoformat(),
|
"start": now.isoformat(),
|
||||||
"end": (now + timedelta(minutes=5)).isoformat(),
|
"end": (now + timedelta(minutes=5)).isoformat(),
|
||||||
"mean": approx(value),
|
"mean": approx(10),
|
||||||
"min": approx(value),
|
"min": approx(10),
|
||||||
"max": approx(value),
|
"max": approx(10),
|
||||||
"last_reset": None,
|
"last_reset": None,
|
||||||
"state": None,
|
"state": None,
|
||||||
"sum": None,
|
"sum": None,
|
||||||
@ -388,32 +373,21 @@ async def test_statistics_during_period_invalid_unit_conversion(
|
|||||||
assert response["error"]["code"] == "invalid_format"
|
assert response["error"]["code"] == "invalid_format"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"units, attributes, state, value",
|
|
||||||
[
|
|
||||||
(IMPERIAL_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, 10, 10),
|
|
||||||
(METRIC_SYSTEM, POWER_SENSOR_KW_ATTRIBUTES, 10, 10),
|
|
||||||
(IMPERIAL_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, 10, 10),
|
|
||||||
(METRIC_SYSTEM, TEMPERATURE_SENSOR_C_ATTRIBUTES, 10, 10),
|
|
||||||
(IMPERIAL_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, 1000, 1000),
|
|
||||||
(METRIC_SYSTEM, PRESSURE_SENSOR_HPA_ATTRIBUTES, 1000, 1000),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_statistics_during_period_in_the_past(
|
async def test_statistics_during_period_in_the_past(
|
||||||
hass, hass_ws_client, recorder_mock, units, attributes, state, value
|
hass, hass_ws_client, recorder_mock
|
||||||
):
|
):
|
||||||
"""Test statistics_during_period in the past."""
|
"""Test statistics_during_period in the past."""
|
||||||
hass.config.set_time_zone("UTC")
|
hass.config.set_time_zone("UTC")
|
||||||
now = dt_util.utcnow().replace()
|
now = dt_util.utcnow().replace()
|
||||||
|
|
||||||
hass.config.units = units
|
hass.config.units = IMPERIAL_SYSTEM
|
||||||
await async_setup_component(hass, "sensor", {})
|
await async_setup_component(hass, "sensor", {})
|
||||||
await async_recorder_block_till_done(hass)
|
await async_recorder_block_till_done(hass)
|
||||||
|
|
||||||
past = now - timedelta(days=3)
|
past = now - timedelta(days=3)
|
||||||
|
|
||||||
with freeze_time(past):
|
with freeze_time(past):
|
||||||
hass.states.async_set("sensor.test", state, attributes=attributes)
|
hass.states.async_set("sensor.test", 10, attributes=POWER_SENSOR_KW_ATTRIBUTES)
|
||||||
await async_wait_recording_done(hass)
|
await async_wait_recording_done(hass)
|
||||||
|
|
||||||
sensor_state = hass.states.get("sensor.test")
|
sensor_state = hass.states.get("sensor.test")
|
||||||
@ -470,9 +444,9 @@ async def test_statistics_during_period_in_the_past(
|
|||||||
"statistic_id": "sensor.test",
|
"statistic_id": "sensor.test",
|
||||||
"start": stats_start.isoformat(),
|
"start": stats_start.isoformat(),
|
||||||
"end": (stats_start + timedelta(minutes=5)).isoformat(),
|
"end": (stats_start + timedelta(minutes=5)).isoformat(),
|
||||||
"mean": approx(value),
|
"mean": approx(10),
|
||||||
"min": approx(value),
|
"min": approx(10),
|
||||||
"max": approx(value),
|
"max": approx(10),
|
||||||
"last_reset": None,
|
"last_reset": None,
|
||||||
"state": None,
|
"state": None,
|
||||||
"sum": None,
|
"sum": None,
|
||||||
@ -498,9 +472,9 @@ async def test_statistics_during_period_in_the_past(
|
|||||||
"statistic_id": "sensor.test",
|
"statistic_id": "sensor.test",
|
||||||
"start": start_of_day.isoformat(),
|
"start": start_of_day.isoformat(),
|
||||||
"end": (start_of_day + timedelta(days=1)).isoformat(),
|
"end": (start_of_day + timedelta(days=1)).isoformat(),
|
||||||
"mean": approx(value),
|
"mean": approx(10),
|
||||||
"min": approx(value),
|
"min": approx(10),
|
||||||
"max": approx(value),
|
"max": approx(10),
|
||||||
"last_reset": None,
|
"last_reset": None,
|
||||||
"state": None,
|
"state": None,
|
||||||
"sum": None,
|
"sum": None,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user