Event automation fuzzy matches on data
This commit is contained in:
parent
6c1f44242c
commit
9019d654d7
2 changed files with 5 additions and 3 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue