Fix logbook filtering entities (#18721)

* Fix logbook filtering entities

* Fix flaky test
This commit is contained in:
Paulus Schoutsen 2018-11-26 19:53:24 +01:00 committed by GitHub
parent 1f123ebcc1
commit 9894eff732
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -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)

View File

@ -62,6 +62,12 @@ class TestComponentLogbook(unittest.TestCase):
# 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]