This commit is contained in:
Paulus Schoutsen 2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View file

@ -11,38 +11,37 @@ import homeassistant.helpers.config_validation as cv
from . import DOMAIN as AUTOMATION_DOMAIN
DEPENDENCIES = ('webhook',)
DEPENDENCIES = ("webhook",)
_LOGGER = logging.getLogger(__name__)
TRIGGER_SCHEMA = vol.Schema({
vol.Required(CONF_PLATFORM): 'webhook',
vol.Required(CONF_WEBHOOK_ID): cv.string,
})
TRIGGER_SCHEMA = vol.Schema(
{vol.Required(CONF_PLATFORM): "webhook", vol.Required(CONF_WEBHOOK_ID): cv.string}
)
async def _handle_webhook(action, hass, webhook_id, request):
"""Handle incoming webhook."""
result = {
'platform': 'webhook',
'webhook_id': webhook_id,
}
result = {"platform": "webhook", "webhook_id": webhook_id}
if 'json' in request.headers.get(hdrs.CONTENT_TYPE, ''):
result['json'] = await request.json()
if "json" in request.headers.get(hdrs.CONTENT_TYPE, ""):
result["json"] = await request.json()
else:
result['data'] = await request.post()
result["data"] = await request.post()
result['query'] = request.query
hass.async_run_job(action, {'trigger': result})
result["query"] = request.query
hass.async_run_job(action, {"trigger": result})
async def async_trigger(hass, config, action, automation_info):
"""Trigger based on incoming webhooks."""
webhook_id = config.get(CONF_WEBHOOK_ID)
hass.components.webhook.async_register(
AUTOMATION_DOMAIN, automation_info['name'],
webhook_id, partial(_handle_webhook, action))
AUTOMATION_DOMAIN,
automation_info["name"],
webhook_id,
partial(_handle_webhook, action),
)
@callback
def unregister():