Add statistics meta data table (#52331)

* Add statistics meta data table

* Tweak meta data generation
This commit is contained in:
Erik Montnemery
2021-06-30 13:32:17 +02:00
committed by GitHub
parent d8337cf98f
commit 0ab999738b
7 changed files with 126 additions and 25 deletions

View File

@@ -951,7 +951,11 @@ async def test_list_statistic_ids(hass, hass_ws_client):
hass.states.async_set(
"sensor.test",
10,
attributes={"device_class": "temperature", "state_class": "measurement"},
attributes={
"device_class": "temperature",
"state_class": "measurement",
"unit_of_measurement": "°C",
},
)
await hass.async_block_till_done()
@@ -962,7 +966,7 @@ async def test_list_statistic_ids(hass, hass_ws_client):
await client.send_json({"id": 1, "type": "history/list_statistic_ids"})
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"statistic_ids": []}
assert response["result"] == []
hass.data[recorder.DATA_INSTANCE].do_adhoc_statistics(period="hourly", start=now)
await hass.async_add_executor_job(hass.data[recorder.DATA_INSTANCE].block_till_done)
@@ -970,25 +974,31 @@ async def test_list_statistic_ids(hass, hass_ws_client):
await client.send_json({"id": 2, "type": "history/list_statistic_ids"})
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"statistic_ids": ["sensor.test"]}
assert response["result"] == [
{"statistic_id": "sensor.test", "unit_of_measurement": "°C"}
]
await client.send_json(
{"id": 3, "type": "history/list_statistic_ids", "statistic_type": "dogs"}
)
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"statistic_ids": ["sensor.test"]}
assert response["result"] == [
{"statistic_id": "sensor.test", "unit_of_measurement": "°C"}
]
await client.send_json(
{"id": 4, "type": "history/list_statistic_ids", "statistic_type": "mean"}
)
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"statistic_ids": ["sensor.test"]}
assert response["result"] == [
{"statistic_id": "sensor.test", "unit_of_measurement": "°C"}
]
await client.send_json(
{"id": 5, "type": "history/list_statistic_ids", "statistic_type": "sum"}
)
response = await client.receive_json()
assert response["success"]
assert response["result"] == {"statistic_ids": []}
assert response["result"] == []