mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Avoid asking recorder platforms for list_statistic_ids when already complete (#88495)
* Avoid asking recorder platforms for list_statistic_ids when already complete If we already had all the data needed for list_statistic_ids, we would still query recorder platforms and throw away the results * Update homeassistant/components/recorder/statistics.py
This commit is contained in:
parent
5bf3a0b7af
commit
9c82cfecca
@ -987,6 +987,7 @@ def list_statistic_ids(
|
|||||||
period.
|
period.
|
||||||
"""
|
"""
|
||||||
result = {}
|
result = {}
|
||||||
|
statistic_ids_set = set(statistic_ids) if statistic_ids else None
|
||||||
|
|
||||||
# Query the database
|
# Query the database
|
||||||
with session_scope(hass=hass) as session:
|
with session_scope(hass=hass) as session:
|
||||||
@ -1009,26 +1010,31 @@ def list_statistic_ids(
|
|||||||
for _, meta in metadata.values()
|
for _, meta in metadata.values()
|
||||||
}
|
}
|
||||||
|
|
||||||
# Query all integrations with a registered recorder platform
|
if not statistic_ids_set or statistic_ids_set.difference(result):
|
||||||
for platform in hass.data[DOMAIN].recorder_platforms.values():
|
# If we want all statistic_ids, or some are missing, we need to query
|
||||||
if not hasattr(platform, "list_statistic_ids"):
|
# the integrations for the missing ones.
|
||||||
continue
|
#
|
||||||
platform_statistic_ids = platform.list_statistic_ids(
|
# Query all integrations with a registered recorder platform
|
||||||
hass, statistic_ids=statistic_ids, statistic_type=statistic_type
|
for platform in hass.data[DOMAIN].recorder_platforms.values():
|
||||||
)
|
if not hasattr(platform, "list_statistic_ids"):
|
||||||
|
|
||||||
for key, meta in platform_statistic_ids.items():
|
|
||||||
if key in result:
|
|
||||||
continue
|
continue
|
||||||
result[key] = {
|
platform_statistic_ids = platform.list_statistic_ids(
|
||||||
"display_unit_of_measurement": meta["unit_of_measurement"],
|
hass, statistic_ids=statistic_ids, statistic_type=statistic_type
|
||||||
"has_mean": meta["has_mean"],
|
)
|
||||||
"has_sum": meta["has_sum"],
|
|
||||||
"name": meta["name"],
|
for key, meta in platform_statistic_ids.items():
|
||||||
"source": meta["source"],
|
if key in result:
|
||||||
"unit_class": _get_unit_class(meta["unit_of_measurement"]),
|
# The database has a higher priority than the integration
|
||||||
"unit_of_measurement": meta["unit_of_measurement"],
|
continue
|
||||||
}
|
result[key] = {
|
||||||
|
"display_unit_of_measurement": meta["unit_of_measurement"],
|
||||||
|
"has_mean": meta["has_mean"],
|
||||||
|
"has_sum": meta["has_sum"],
|
||||||
|
"name": meta["name"],
|
||||||
|
"source": meta["source"],
|
||||||
|
"unit_class": _get_unit_class(meta["unit_of_measurement"]),
|
||||||
|
"unit_of_measurement": meta["unit_of_measurement"],
|
||||||
|
}
|
||||||
|
|
||||||
# Return a list of statistic_id + metadata
|
# Return a list of statistic_id + metadata
|
||||||
return [
|
return [
|
||||||
|
Loading…
x
Reference in New Issue
Block a user