Fix typing on recorder.history (#68917)

This commit is contained in:
J. Nick Koston 2022-03-30 09:50:21 -10:00 committed by GitHub
parent 9c2a944997
commit 8b04c676ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,7 @@ from datetime import datetime
from itertools import groupby from itertools import groupby
import logging import logging
import time import time
from typing import Any from typing import Any, cast
from sqlalchemy import Column, Text, and_, bindparam, func, or_ from sqlalchemy import Column, Text, and_, bindparam, func, or_
from sqlalchemy.ext import baked from sqlalchemy.ext import baked
@ -262,7 +262,7 @@ def state_changes_during_period(
descending: bool = False, descending: bool = False,
limit: int | None = None, limit: int | None = None,
include_start_time_state: bool = True, include_start_time_state: bool = True,
) -> MutableMapping[str, Iterable[LazyState | State | dict[str, Any]]]: ) -> MutableMapping[str, Iterable[LazyState]]:
"""Return states changes during UTC period start_time - end_time.""" """Return states changes during UTC period start_time - end_time."""
with session_scope(hass=hass) as session: with session_scope(hass=hass) as session:
baked_query, join_attributes = bake_query_and_join_attributes( baked_query, join_attributes = bake_query_and_join_attributes(
@ -302,19 +302,22 @@ def state_changes_during_period(
entity_ids = [entity_id] if entity_id is not None else None entity_ids = [entity_id] if entity_id is not None else None
return _sorted_states_to_dict( return cast(
hass, MutableMapping[str, Iterable[LazyState]],
session, _sorted_states_to_dict(
states, hass,
start_time, session,
entity_ids, states,
include_start_time_state=include_start_time_state, start_time,
entity_ids,
include_start_time_state=include_start_time_state,
),
) )
def get_last_state_changes( def get_last_state_changes(
hass: HomeAssistant, number_of_states: int, entity_id: str hass: HomeAssistant, number_of_states: int, entity_id: str
) -> MutableMapping[str, Iterable[LazyState | State | dict[str, Any]]]: ) -> MutableMapping[str, Iterable[LazyState]]:
"""Return the last number_of_states.""" """Return the last number_of_states."""
start_time = dt_util.utcnow() start_time = dt_util.utcnow()
@ -345,13 +348,16 @@ def get_last_state_changes(
entity_ids = [entity_id] if entity_id is not None else None entity_ids = [entity_id] if entity_id is not None else None
return _sorted_states_to_dict( return cast(
hass, MutableMapping[str, Iterable[LazyState]],
session, _sorted_states_to_dict(
reversed(states), hass,
start_time, session,
entity_ids, reversed(states),
include_start_time_state=False, start_time,
entity_ids,
include_start_time_state=False,
),
) )