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:
J. Nick Koston 2023-03-19 16:05:07 -10:00 committed by GitHub
parent aebe4c66a6
commit f27d73fc34
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 1 additions and 43 deletions

View file

@ -12,12 +12,7 @@ from homeassistant.components.recorder.db_schema import (
States,
)
from .common import (
apply_states_filters,
legacy_select_events_context_id,
select_events_without_states,
select_states,
)
from .common import apply_states_filters, select_events_without_states, select_states
def all_stmt(
@ -33,9 +28,6 @@ def all_stmt(
lambda: select_events_without_states(start_day, end_day, event_types)
)
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(
_states_query_for_context_id(
start_day,
@ -43,12 +35,6 @@ def all_stmt(
# https://github.com/python/mypy/issues/2608
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:
if events_entity_filter is not None:

View file

@ -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:
"""Filter states by time range.