Merge pull request #405 from balloob/automation-event

Event automation fuzzy matches on data
pull/409/head
Paulus Schoutsen 2015-09-19 10:43:02 -07:00
commit 55f6ff86e4
2 changed files with 5 additions and 3 deletions

View File

@ -20,11 +20,12 @@ def trigger(hass, config, action):
_LOGGER.error("Missing configuration key %s", CONF_EVENT_TYPE)
return False
event_data = config.get(CONF_EVENT_DATA, {})
event_data = config.get(CONF_EVENT_DATA)
def handle_event(event):
""" Listens for events and calls the action when data matches. """
if event_data == event.data:
if not event_data or all(val == event.data.get(key) for key, val
in event_data.items()):
action()
hass.bus.listen(event_type, handle_event)

View File

@ -98,7 +98,8 @@ class TestAutomationEvent(unittest.TestCase):
}
}))
self.hass.bus.fire('test_event', {'some_attr': 'some_value'})
self.hass.bus.fire('test_event', {'some_attr': 'some_value',
'another': 'value'})
self.hass.pool.block_till_done()
self.assertEqual(1, len(self.calls))