mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
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:
parent
05ba78d886
commit
4e7cc110d9
@ -21,7 +21,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
TRIGGER_SCHEMA = vol.Schema({
|
TRIGGER_SCHEMA = vol.Schema({
|
||||||
vol.Required(CONF_PLATFORM): 'event',
|
vol.Required(CONF_PLATFORM): 'event',
|
||||||
vol.Required(CONF_EVENT_TYPE): cv.string,
|
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_type = config.get(CONF_EVENT_TYPE)
|
||||||
event_data_schema = vol.Schema(
|
event_data_schema = vol.Schema(
|
||||||
config.get(CONF_EVENT_DATA),
|
config.get(CONF_EVENT_DATA),
|
||||||
extra=vol.ALLOW_EXTRA)
|
extra=vol.ALLOW_EXTRA) if CONF_EVENT_DATA in config else None
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def handle_event(event):
|
def handle_event(event):
|
||||||
"""Listen for events and calls the action when data matches."""
|
"""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:
|
try:
|
||||||
event_data_schema(event.data)
|
event_data_schema(event.data)
|
||||||
except vol.Invalid:
|
except vol.Invalid:
|
||||||
|
@ -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.hass.block_till_done()
|
||||||
self.assertEqual(1, len(self.calls))
|
self.assertEqual(1, len(self.calls))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user