Remove legacy event lookups from logbook (#89945)
Events recorded with Home Assistant 2022.5.x or older will no longer display context information in the logbook
This commit is contained in:
parent
aebe4c66a6
commit
f27d73fc34
2 changed files with 1 additions and 43 deletions
|
@ -12,12 +12,7 @@ from homeassistant.components.recorder.db_schema import (
|
||||||
States,
|
States,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .common import (
|
from .common import apply_states_filters, select_events_without_states, select_states
|
||||||
apply_states_filters,
|
|
||||||
legacy_select_events_context_id,
|
|
||||||
select_events_without_states,
|
|
||||||
select_states,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def all_stmt(
|
def all_stmt(
|
||||||
|
@ -33,9 +28,6 @@ def all_stmt(
|
||||||
lambda: select_events_without_states(start_day, end_day, event_types)
|
lambda: select_events_without_states(start_day, end_day, event_types)
|
||||||
)
|
)
|
||||||
if context_id_bin is not None:
|
if context_id_bin is not None:
|
||||||
# Once all the old `state_changed` events
|
|
||||||
# are gone from the database remove the
|
|
||||||
# _legacy_select_events_context_id()
|
|
||||||
stmt += lambda s: s.where(Events.context_id_bin == context_id_bin).union_all(
|
stmt += lambda s: s.where(Events.context_id_bin == context_id_bin).union_all(
|
||||||
_states_query_for_context_id(
|
_states_query_for_context_id(
|
||||||
start_day,
|
start_day,
|
||||||
|
@ -43,12 +35,6 @@ def all_stmt(
|
||||||
# https://github.com/python/mypy/issues/2608
|
# https://github.com/python/mypy/issues/2608
|
||||||
context_id_bin, # type:ignore[arg-type]
|
context_id_bin, # type:ignore[arg-type]
|
||||||
),
|
),
|
||||||
legacy_select_events_context_id(
|
|
||||||
start_day,
|
|
||||||
end_day,
|
|
||||||
# https://github.com/python/mypy/issues/2608
|
|
||||||
context_id_bin, # type:ignore[arg-type]
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if events_entity_filter is not None:
|
if events_entity_filter is not None:
|
||||||
|
|
|
@ -166,34 +166,6 @@ def select_states() -> Select:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def legacy_select_events_context_id(
|
|
||||||
start_day: float, end_day: float, context_id_bin: bytes
|
|
||||||
) -> Select:
|
|
||||||
"""Generate a legacy events context id select that also joins states."""
|
|
||||||
# This can be removed once we no longer have event_ids in the states table
|
|
||||||
return (
|
|
||||||
select(
|
|
||||||
*EVENT_COLUMNS,
|
|
||||||
literal(value=None, type_=sqlalchemy.String).label("shared_data"),
|
|
||||||
*STATE_COLUMNS,
|
|
||||||
NOT_CONTEXT_ONLY,
|
|
||||||
)
|
|
||||||
.outerjoin(States, (Events.event_id == States.event_id))
|
|
||||||
.where(
|
|
||||||
(States.last_updated_ts == States.last_changed_ts)
|
|
||||||
| States.last_changed_ts.is_(None)
|
|
||||||
)
|
|
||||||
.where(_not_continuous_entity_matcher())
|
|
||||||
.outerjoin(
|
|
||||||
StateAttributes, (States.attributes_id == StateAttributes.attributes_id)
|
|
||||||
)
|
|
||||||
.outerjoin(StatesMeta, (States.metadata_id == StatesMeta.metadata_id))
|
|
||||||
.outerjoin(EventTypes, (Events.event_type_id == EventTypes.event_type_id))
|
|
||||||
.where((Events.time_fired_ts > start_day) & (Events.time_fired_ts < end_day))
|
|
||||||
.where(Events.context_id_bin == context_id_bin)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def apply_states_filters(sel: Select, start_day: float, end_day: float) -> Select:
|
def apply_states_filters(sel: Select, start_day: float, end_day: float) -> Select:
|
||||||
"""Filter states by time range.
|
"""Filter states by time range.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue