mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 23:07:09 +00:00
Move imports to top for history (#29484)
This commit is contained in:
parent
95de802fbd
commit
bbe57d6673
@ -5,22 +5,23 @@ from itertools import groupby
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
from sqlalchemy import and_, func
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
|
from homeassistant.components import recorder, script
|
||||||
|
from homeassistant.components.http import HomeAssistantView
|
||||||
|
from homeassistant.components.recorder.models import States
|
||||||
|
from homeassistant.components.recorder.util import execute, session_scope
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
HTTP_BAD_REQUEST,
|
ATTR_HIDDEN,
|
||||||
CONF_DOMAINS,
|
CONF_DOMAINS,
|
||||||
CONF_ENTITIES,
|
CONF_ENTITIES,
|
||||||
CONF_EXCLUDE,
|
CONF_EXCLUDE,
|
||||||
CONF_INCLUDE,
|
CONF_INCLUDE,
|
||||||
|
HTTP_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
import homeassistant.util.dt as dt_util
|
|
||||||
from homeassistant.components import recorder, script
|
|
||||||
from homeassistant.components.http import HomeAssistantView
|
|
||||||
from homeassistant.const import ATTR_HIDDEN
|
|
||||||
from homeassistant.components.recorder.util import session_scope, execute
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
# mypy: allow-untyped-defs, no-check-untyped-defs
|
# mypy: allow-untyped-defs, no-check-untyped-defs
|
||||||
|
|
||||||
@ -58,7 +59,6 @@ def get_significant_states(
|
|||||||
thermostat so that we get current temperature in our graphs).
|
thermostat so that we get current temperature in our graphs).
|
||||||
"""
|
"""
|
||||||
timer_start = time.perf_counter()
|
timer_start = time.perf_counter()
|
||||||
from homeassistant.components.recorder.models import States
|
|
||||||
|
|
||||||
with session_scope(hass=hass) as session:
|
with session_scope(hass=hass) as session:
|
||||||
query = session.query(States).filter(
|
query = session.query(States).filter(
|
||||||
@ -94,7 +94,6 @@ def get_significant_states(
|
|||||||
|
|
||||||
def state_changes_during_period(hass, start_time, end_time=None, entity_id=None):
|
def state_changes_during_period(hass, start_time, end_time=None, entity_id=None):
|
||||||
"""Return states changes during UTC period start_time - end_time."""
|
"""Return states changes during UTC period start_time - end_time."""
|
||||||
from homeassistant.components.recorder.models import States
|
|
||||||
|
|
||||||
with session_scope(hass=hass) as session:
|
with session_scope(hass=hass) as session:
|
||||||
query = session.query(States).filter(
|
query = session.query(States).filter(
|
||||||
@ -117,7 +116,6 @@ def state_changes_during_period(hass, start_time, end_time=None, entity_id=None)
|
|||||||
|
|
||||||
def get_last_state_changes(hass, number_of_states, entity_id):
|
def get_last_state_changes(hass, number_of_states, entity_id):
|
||||||
"""Return the last number_of_states."""
|
"""Return the last number_of_states."""
|
||||||
from homeassistant.components.recorder.models import States
|
|
||||||
|
|
||||||
start_time = dt_util.utcnow()
|
start_time = dt_util.utcnow()
|
||||||
|
|
||||||
@ -142,7 +140,6 @@ def get_last_state_changes(hass, number_of_states, entity_id):
|
|||||||
|
|
||||||
def get_states(hass, utc_point_in_time, entity_ids=None, run=None, filters=None):
|
def get_states(hass, utc_point_in_time, entity_ids=None, run=None, filters=None):
|
||||||
"""Return the states at a specific point in time."""
|
"""Return the states at a specific point in time."""
|
||||||
from homeassistant.components.recorder.models import States
|
|
||||||
|
|
||||||
if run is None:
|
if run is None:
|
||||||
run = recorder.run_information(hass, utc_point_in_time)
|
run = recorder.run_information(hass, utc_point_in_time)
|
||||||
@ -151,8 +148,6 @@ def get_states(hass, utc_point_in_time, entity_ids=None, run=None, filters=None)
|
|||||||
if run is None:
|
if run is None:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
from sqlalchemy import and_, func
|
|
||||||
|
|
||||||
with session_scope(hass=hass) as session:
|
with session_scope(hass=hass) as session:
|
||||||
query = session.query(States)
|
query = session.query(States)
|
||||||
|
|
||||||
@ -386,7 +381,6 @@ class Filters:
|
|||||||
* if include and exclude is defined - select the entities specified in
|
* if include and exclude is defined - select the entities specified in
|
||||||
the include and filter out the ones from the exclude list.
|
the include and filter out the ones from the exclude list.
|
||||||
"""
|
"""
|
||||||
from homeassistant.components.recorder.models import States
|
|
||||||
|
|
||||||
# specific entities requested - do not in/exclude anything
|
# specific entities requested - do not in/exclude anything
|
||||||
if entity_ids is not None:
|
if entity_ids is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user