mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Merge pull request #405 from balloob/automation-event
Event automation fuzzy matches on data
This commit is contained in:
commit
55f6ff86e4
@ -20,11 +20,12 @@ def trigger(hass, config, action):
|
|||||||
_LOGGER.error("Missing configuration key %s", CONF_EVENT_TYPE)
|
_LOGGER.error("Missing configuration key %s", CONF_EVENT_TYPE)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
event_data = config.get(CONF_EVENT_DATA, {})
|
event_data = config.get(CONF_EVENT_DATA)
|
||||||
|
|
||||||
def handle_event(event):
|
def handle_event(event):
|
||||||
""" Listens for events and calls the action when data matches. """
|
""" 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()
|
action()
|
||||||
|
|
||||||
hass.bus.listen(event_type, handle_event)
|
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.hass.pool.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user