Reduce size of get_statistics_during_period WS API response (#82131)

This commit is contained in:
Erik Montnemery 2022-11-16 17:36:30 +01:00 committed by GitHub
parent bb64b39d0e
commit 607a0e7697
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 588 additions and 591 deletions

View file

@ -450,7 +450,7 @@ def _compile_statistics( # noqa: C901
to_query.append(entity_id)
last_stats = statistics.get_latest_short_term_statistics(
hass, to_query, metadata=old_metadatas
hass, to_query, {"last_reset", "state", "sum"}, metadata=old_metadatas
)
for ( # pylint: disable=too-many-nested-blocks
entity_id,
@ -508,6 +508,8 @@ def _compile_statistics( # noqa: C901
if entity_id in last_stats:
# We have compiled history for this sensor before, use that as a starting point
last_reset = old_last_reset = last_stats[entity_id][0]["last_reset"]
if old_last_reset is not None:
last_reset = old_last_reset = old_last_reset.isoformat()
new_state = old_state = last_stats[entity_id][0]["state"]
_sum = last_stats[entity_id][0]["sum"] or 0.0