Return empty when listing statistic_ids for unsupported statistic (#52954)

pull/52823/head
Erik Montnemery 2021-07-13 10:35:55 +02:00 committed by GitHub
parent 9cbf88d944
commit c5556a091e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -145,8 +145,10 @@ def _get_metadata(hass, session, statistic_ids, statistic_type):
)
if statistic_type == "mean":
baked_query += lambda q: q.filter(StatisticsMeta.has_mean.isnot(False))
if statistic_type == "sum":
elif statistic_type == "sum":
baked_query += lambda q: q.filter(StatisticsMeta.has_sum.isnot(False))
elif statistic_type is not None:
return {}
result = execute(baked_query(session).params(statistic_ids=statistic_ids))
metadata_ids = [metadata[0] for metadata in result]

View File

@ -1015,9 +1015,7 @@ async def test_list_statistic_ids(hass, hass_ws_client, units, attributes, unit)
)
response = await client.receive_json()
assert response["success"]
assert response["result"] == [
{"statistic_id": "sensor.test", "unit_of_measurement": unit}
]
assert response["result"] == []
await client.send_json(
{"id": 4, "type": "history/list_statistic_ids", "statistic_type": "mean"}