Merge pull request #405 from balloob/automation-event
Event automation fuzzy matches on datapull/409/head
commit
55f6ff86e4
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
|
Loading…
Reference in New Issue