diff --git a/homeassistant/components/recorder/statistics.py b/homeassistant/components/recorder/statistics.py index 2ef49df7ded..4ddf380ee3a 100644 --- a/homeassistant/components/recorder/statistics.py +++ b/homeassistant/components/recorder/statistics.py @@ -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] diff --git a/tests/components/history/test_init.py b/tests/components/history/test_init.py index c4f85717cac..df4a59a372c 100644 --- a/tests/components/history/test_init.py +++ b/tests/components/history/test_init.py @@ -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"}