mirror of
https://github.com/home-assistant/core.git
synced 2025-08-14 18:11:41 +02:00
postgresql
This commit is contained in:
@@ -28,7 +28,7 @@ from homeassistant.core import HomeAssistant, State, split_entity_id
|
|||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from ... import recorder
|
from ... import recorder
|
||||||
from ..db_schema import StateAttributes, States
|
from ..db_schema import DOUBLE_TYPE, StateAttributes, States
|
||||||
from ..filters import Filters
|
from ..filters import Filters
|
||||||
from ..models import (
|
from ..models import (
|
||||||
LazyState,
|
LazyState,
|
||||||
@@ -72,9 +72,13 @@ def _stmt_and_join_attributes_for_start_state(
|
|||||||
) -> Select:
|
) -> Select:
|
||||||
"""Return the statement and if StateAttributes should be joined."""
|
"""Return the statement and if StateAttributes should be joined."""
|
||||||
_select = select(States.metadata_id, States.state)
|
_select = select(States.metadata_id, States.state)
|
||||||
_select = _select.add_columns(literal(value=None).label("last_updated_ts"))
|
_select = _select.add_columns(
|
||||||
|
literal(value=None).label("last_updated_ts").cast(DOUBLE_TYPE)
|
||||||
|
)
|
||||||
if include_last_changed:
|
if include_last_changed:
|
||||||
_select = _select.add_columns(literal(value=None).label("last_changed_ts"))
|
_select = _select.add_columns(
|
||||||
|
literal(value=None).label("last_changed_ts").cast(DOUBLE_TYPE)
|
||||||
|
)
|
||||||
if not no_attributes:
|
if not no_attributes:
|
||||||
_select = _select.add_columns(States.attributes, StateAttributes.shared_attrs)
|
_select = _select.add_columns(States.attributes, StateAttributes.shared_attrs)
|
||||||
return _select
|
return _select
|
||||||
@@ -339,23 +343,26 @@ def _state_changed_during_period_stmt(
|
|||||||
stmt = stmt.limit(limit)
|
stmt = stmt.limit(limit)
|
||||||
if not include_start_time_state or not run_start_ts:
|
if not include_start_time_state or not run_start_ts:
|
||||||
return stmt
|
return stmt
|
||||||
return _select_from_subquery(
|
start_time_subquery = _select_from_subquery(
|
||||||
union_all(
|
_get_single_entity_start_time_stmt(
|
||||||
_select_from_subquery(
|
start_time_ts,
|
||||||
_get_single_entity_start_time_stmt(
|
single_metadata_id,
|
||||||
start_time_ts,
|
no_attributes,
|
||||||
single_metadata_id,
|
False,
|
||||||
no_attributes,
|
|
||||||
False,
|
|
||||||
).subquery(),
|
|
||||||
no_attributes,
|
|
||||||
False,
|
|
||||||
),
|
|
||||||
_select_from_subquery(stmt.subquery(), no_attributes, False),
|
|
||||||
).subquery(),
|
).subquery(),
|
||||||
no_attributes,
|
no_attributes,
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
|
main_subquery = _select_from_subquery(stmt.subquery(), no_attributes, False)
|
||||||
|
if descending:
|
||||||
|
inner_queries = [main_subquery, start_time_subquery]
|
||||||
|
else:
|
||||||
|
inner_queries = [start_time_subquery, main_subquery]
|
||||||
|
return _select_from_subquery(
|
||||||
|
union_all(*inner_queries).subquery(),
|
||||||
|
no_attributes,
|
||||||
|
False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def state_changes_during_period(
|
def state_changes_during_period(
|
||||||
|
Reference in New Issue
Block a user