mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Add setup type hints to history (#63441)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
c60bb1890d
commit
533c377bd1
@ -28,6 +28,7 @@ from homeassistant.helpers.entityfilter import (
|
|||||||
CONF_ENTITY_GLOBS,
|
CONF_ENTITY_GLOBS,
|
||||||
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA,
|
INCLUDE_EXCLUDE_BASE_FILTER_SCHEMA,
|
||||||
)
|
)
|
||||||
|
from homeassistant.helpers.typing import ConfigType
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
@ -88,7 +89,7 @@ def get_state(hass, utc_point_in_time, entity_id, run=None):
|
|||||||
return history.get_state(hass, utc_point_in_time, entity_id, run=None)
|
return history.get_state(hass, utc_point_in_time, entity_id, run=None)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the history hooks."""
|
"""Set up the history hooks."""
|
||||||
conf = config.get(DOMAIN, {})
|
conf = config.get(DOMAIN, {})
|
||||||
|
|
||||||
@ -182,7 +183,7 @@ class HistoryPeriodView(HomeAssistantView):
|
|||||||
name = "api:history:view-period"
|
name = "api:history:view-period"
|
||||||
extra_urls = ["/api/history/period/{datetime}"]
|
extra_urls = ["/api/history/period/{datetime}"]
|
||||||
|
|
||||||
def __init__(self, filters, use_include_order):
|
def __init__(self, filters: Filters | None, use_include_order: bool) -> None:
|
||||||
"""Initialize the history period view."""
|
"""Initialize the history period view."""
|
||||||
self.filters = filters
|
self.filters = filters
|
||||||
self.use_include_order = use_include_order
|
self.use_include_order = use_include_order
|
||||||
@ -294,7 +295,7 @@ class HistoryPeriodView(HomeAssistantView):
|
|||||||
return self.json(result)
|
return self.json(result)
|
||||||
|
|
||||||
|
|
||||||
def sqlalchemy_filter_from_include_exclude_conf(conf):
|
def sqlalchemy_filter_from_include_exclude_conf(conf: ConfigType) -> Filters | None:
|
||||||
"""Build a sql filter from config."""
|
"""Build a sql filter from config."""
|
||||||
filters = Filters()
|
filters = Filters()
|
||||||
if exclude := conf.get(CONF_EXCLUDE):
|
if exclude := conf.get(CONF_EXCLUDE):
|
||||||
@ -312,15 +313,15 @@ def sqlalchemy_filter_from_include_exclude_conf(conf):
|
|||||||
class Filters:
|
class Filters:
|
||||||
"""Container for the configured include and exclude filters."""
|
"""Container for the configured include and exclude filters."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
"""Initialise the include and exclude filters."""
|
"""Initialise the include and exclude filters."""
|
||||||
self.excluded_entities = []
|
self.excluded_entities: list[str] = []
|
||||||
self.excluded_domains = []
|
self.excluded_domains: list[str] = []
|
||||||
self.excluded_entity_globs = []
|
self.excluded_entity_globs: list[str] = []
|
||||||
|
|
||||||
self.included_entities = []
|
self.included_entities: list[str] = []
|
||||||
self.included_domains = []
|
self.included_domains: list[str] = []
|
||||||
self.included_entity_globs = []
|
self.included_entity_globs: list[str] = []
|
||||||
|
|
||||||
def apply(self, query):
|
def apply(self, query):
|
||||||
"""Apply the entity filter."""
|
"""Apply the entity filter."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user