Ensure removed entities are not displayed in logbook (#37395)
This commit is contained in:
1 parent
045cdee30c
commit
4b2ebf5487
5 files changed
+121
-98
No files matched your search
@@ -355,7 +355,7 @@ def _get_events(
|
||||
"""Yield Events that are not filtered away."""
|
||||
for row in query.yield_per(1000):
|
||||
event = LazyEventPartialState(row)
|
||||
if _keep_event(hass, event, entities_filter, entity_attr_cache):
|
||||
if _keep_event(hass, event, entities_filter):
|
||||
yield event
|
||||
|
||||
with session_scope(hass=hass) as session:
|
||||
@@ -375,12 +375,10 @@ def _get_events(
|
||||
Events.event_data,
|
||||
Events.time_fired,
|
||||
Events.context_user_id,
|
||||
States.state_id,
|
||||
States.state,
|
||||
States.entity_id,
|
||||
States.domain,
|
||||
States.attributes,
|
||||
old_state.state_id.label("old_state_id"),
|
||||
)
|
||||
.order_by(Events.time_fired)
|
||||
.outerjoin(States, (Events.event_id == States.event_id))
|
||||
@@ -400,6 +398,7 @@ def _get_events(
|
||||
| (
|
||||
(States.state_id.isnot(None))
|
||||
& (old_state.state_id.isnot(None))
|
||||
& (States.state.isnot(None))
|
||||
& (States.state != old_state.state)
|
||||
)
|
||||
)
|
||||
@@ -444,12 +443,9 @@ def _get_events(
|
||||
return list(humanify(hass, yield_events(query), entity_attr_cache, prev_states))
|
||||
|
||||
|
||||
def _keep_event(hass, event, entities_filter, entity_attr_cache):
|
||||
def _keep_event(hass, event, entities_filter):
|
||||
if event.event_type == EVENT_STATE_CHANGED:
|
||||
entity_id = event.entity_id
|
||||
if entity_id is None:
|
||||
return False
|
||||
|
||||
# Do not report on new entities
|
||||
# Do not report on entity removal
|
||||
if not event.has_old_and_new_state:
|
||||
@@ -650,9 +646,12 @@ class LazyEventPartialState:
|
||||
# Delete this check once all states are saved in the v8 schema
|
||||
# format or later (they have the old_state_id column).
|
||||
|
||||
# New events in v8 schema format
|
||||
# New events in v8+ schema format
|
||||
if self._row.event_data == EMPTY_JSON_OBJECT:
|
||||
return self._row.state_id is not None and self._row.old_state_id is not None
|
||||
# Events are already pre-filtered in sql
|
||||
# to exclude missing old and new state
|
||||
# if they are in v8+ format
|
||||
return True
|
||||
|
||||
# Old events not in v8 schema format
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user