Fix no data event triggers (#10049)

* Test including extra data on a no data trigger

* Match any dicts for default schema for event data

* Fix indentation

* Only check schema if one was configured
This commit is contained in:
Adam Mills 2017-10-22 20:20:38 -04:00 committed by GitHub
parent 05ba78d886
commit 4e7cc110d9
2 changed files with 11 additions and 8 deletions

View File

@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
TRIGGER_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): 'event',
vol.Required(CONF_EVENT_TYPE): cv.string,
vol.Optional(CONF_EVENT_DATA, default={}): dict,
vol.Optional(CONF_EVENT_DATA): dict,
})
@ -31,11 +31,14 @@ def async_trigger(hass, config, action):
event_type = config.get(CONF_EVENT_TYPE)
event_data_schema = vol.Schema(
config.get(CONF_EVENT_DATA),
extra=vol.ALLOW_EXTRA)
extra=vol.ALLOW_EXTRA) if CONF_EVENT_DATA in config else None
@callback
def handle_event(event):
"""Listen for events and calls the action when data matches."""
if event_data_schema:
# Check that the event data matches the configured
# schema if one was provided
try:
event_data_schema(event.data)
except vol.Invalid:

View File

@ -43,7 +43,7 @@ class TestAutomationEvent(unittest.TestCase):
}
})
self.hass.bus.fire('test_event')
self.hass.bus.fire('test_event', {'extra_key': 'extra_data'})
self.hass.block_till_done()
self.assertEqual(1, len(self.calls))