Black
This commit is contained in:
parent
da05dfe708
commit
4de97abc3a
2676 changed files with 163166 additions and 140084 deletions
|
@ -7,24 +7,28 @@ from homeassistant.core import callback
|
|||
from homeassistant.const import CONF_PLATFORM
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
CONF_EVENT_TYPE = 'event_type'
|
||||
CONF_EVENT_DATA = 'event_data'
|
||||
CONF_EVENT_TYPE = "event_type"
|
||||
CONF_EVENT_DATA = "event_data"
|
||||
|
||||
_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): dict,
|
||||
})
|
||||
TRIGGER_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_PLATFORM): "event",
|
||||
vol.Required(CONF_EVENT_TYPE): cv.string,
|
||||
vol.Optional(CONF_EVENT_DATA): dict,
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_trigger(hass, config, action, automation_info):
|
||||
"""Listen for events based on configuration."""
|
||||
event_type = config.get(CONF_EVENT_TYPE)
|
||||
event_data_schema = vol.Schema(
|
||||
config.get(CONF_EVENT_DATA),
|
||||
extra=vol.ALLOW_EXTRA) if config.get(CONF_EVENT_DATA) else None
|
||||
event_data_schema = (
|
||||
vol.Schema(config.get(CONF_EVENT_DATA), extra=vol.ALLOW_EXTRA)
|
||||
if config.get(CONF_EVENT_DATA)
|
||||
else None
|
||||
)
|
||||
|
||||
@callback
|
||||
def handle_event(event):
|
||||
|
@ -38,11 +42,11 @@ async def async_trigger(hass, config, action, automation_info):
|
|||
# If event data doesn't match requested schema, skip event
|
||||
return
|
||||
|
||||
hass.async_run_job(action({
|
||||
'trigger': {
|
||||
'platform': 'event',
|
||||
'event': event,
|
||||
},
|
||||
}, context=event.context))
|
||||
hass.async_run_job(
|
||||
action(
|
||||
{"trigger": {"platform": "event", "event": event}},
|
||||
context=event.context,
|
||||
)
|
||||
)
|
||||
|
||||
return hass.bus.async_listen(event_type, handle_event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue