Cleanup recorder history typing (#69408)
This commit is contained in:
parent
97aa65d9a4
commit
5c7c09726a
4 changed files with 160 additions and 45 deletions
|
@ -7,7 +7,7 @@ import datetime
|
|||
import itertools
|
||||
import logging
|
||||
import math
|
||||
from typing import Any, cast
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy.orm.session import Session
|
||||
|
||||
|
@ -19,7 +19,6 @@ from homeassistant.components.recorder import (
|
|||
)
|
||||
from homeassistant.components.recorder.const import DOMAIN as RECORDER_DOMAIN
|
||||
from homeassistant.components.recorder.models import (
|
||||
LazyState,
|
||||
StatisticData,
|
||||
StatisticMetaData,
|
||||
StatisticResult,
|
||||
|
@ -417,9 +416,9 @@ def _compile_statistics( # noqa: C901
|
|||
entities_full_history = [
|
||||
i.entity_id for i in sensor_states if "sum" in wanted_statistics[i.entity_id]
|
||||
]
|
||||
history_list: MutableMapping[str, Iterable[LazyState | State | dict[str, Any]]] = {}
|
||||
history_list: MutableMapping[str, list[State]] = {}
|
||||
if entities_full_history:
|
||||
history_list = history.get_significant_states_with_session(
|
||||
history_list = history.get_full_significant_states_with_session(
|
||||
hass,
|
||||
session,
|
||||
start - datetime.timedelta.resolution,
|
||||
|
@ -433,7 +432,7 @@ def _compile_statistics( # noqa: C901
|
|||
if "sum" not in wanted_statistics[i.entity_id]
|
||||
]
|
||||
if entities_significant_history:
|
||||
_history_list = history.get_significant_states_with_session(
|
||||
_history_list = history.get_full_significant_states_with_session(
|
||||
hass,
|
||||
session,
|
||||
start - datetime.timedelta.resolution,
|
||||
|
@ -445,7 +444,7 @@ def _compile_statistics( # noqa: C901
|
|||
# from the recorder. Get the state from the state machine instead.
|
||||
for _state in sensor_states:
|
||||
if _state.entity_id not in history_list:
|
||||
history_list[_state.entity_id] = (_state,)
|
||||
history_list[_state.entity_id] = [_state]
|
||||
|
||||
for _state in sensor_states: # pylint: disable=too-many-nested-blocks
|
||||
entity_id = _state.entity_id
|
||||
|
@ -459,9 +458,7 @@ def _compile_statistics( # noqa: C901
|
|||
hass,
|
||||
session,
|
||||
old_metadatas,
|
||||
# entity_history does not contain minimal responses
|
||||
# so we must cast here
|
||||
cast(list[State], entity_history),
|
||||
entity_history,
|
||||
device_class,
|
||||
entity_id,
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue