Skip to content

Commit

Permalink
Fix logbook filtering entities (#18721)
Browse files Browse the repository at this point in the history
* Fix logbook filtering entities

* Fix flaky test
  • Loading branch information
balloob committed Nov 27, 2018
1 parent 775c909 commit f3047b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions homeassistant/components/logbook.py
Expand Up @@ -391,9 +391,9 @@ def _get_events(hass, config, start_day, end_day, entity_id=None):
.filter(Events.event_type.in_(ALL_EVENT_TYPES)) \
.filter((Events.time_fired > start_day)
& (Events.time_fired < end_day)) \
.filter((States.last_updated == States.last_changed)
| (States.state_id.is_(None))) \
.filter(States.entity_id.in_(entity_ids))
.filter(((States.last_updated == States.last_changed) &
States.entity_id.in_(entity_ids))
| (States.state_id.is_(None)))

events = execute(query)

Expand Down
6 changes: 6 additions & 0 deletions tests/components/test_logbook.py
Expand Up @@ -62,6 +62,12 @@ def event_listener(event):
# Our service call will unblock when the event listeners have been
# scheduled. This means that they may not have been processed yet.
self.hass.block_till_done()
self.hass.data[recorder.DATA_INSTANCE].block_till_done()

events = list(logbook._get_events(
self.hass, {}, dt_util.utcnow() - timedelta(hours=1),
dt_util.utcnow() + timedelta(hours=1)))
assert len(events) == 2

assert 1 == len(calls)
last_call = calls[-1]
Expand Down

0 comments on commit f3047b9

Please sign in to comment.