From df580b23227785a9224042a2ceb439e2074a68c5 Mon Sep 17 00:00:00 2001 From: ActuallyRuben Date: Sun, 14 Apr 2019 19:53:35 +0200 Subject: [PATCH] Add URL query parameters to webhook trigger result data (#23043) * Added query parameters to webhook data * Added test for query webhook * Add second blank line in new test for webhook trigger --- .../components/automation/webhook.py | 1 + tests/components/automation/test_webhook.py | 34 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/homeassistant/components/automation/webhook.py b/homeassistant/components/automation/webhook.py index f65b5cf885c..37cab3cb8c0 100644 --- a/homeassistant/components/automation/webhook.py +++ b/homeassistant/components/automation/webhook.py @@ -33,6 +33,7 @@ async def _handle_webhook(action, hass, webhook_id, request): else: result['data'] = await request.post() + result['query'] = request.query hass.async_run_job(action, {'trigger': result}) diff --git a/tests/components/automation/test_webhook.py b/tests/components/automation/test_webhook.py index c42f3805662..bed8de18ed4 100644 --- a/tests/components/automation/test_webhook.py +++ b/tests/components/automation/test_webhook.py @@ -82,3 +82,37 @@ async def test_webhook_post(hass, aiohttp_client): assert len(events) == 1 assert events[0].data['hello'] == 'yo world' + + +async def test_webhook_query(hass, aiohttp_client): + """Test triggering with a query POST webhook.""" + events = [] + + @callback + def store_event(event): + """Helepr to store events.""" + events.append(event) + + hass.bus.async_listen('test_success', store_event) + + assert await async_setup_component(hass, 'automation', { + 'automation': { + 'trigger': { + 'platform': 'webhook', + 'webhook_id': 'query_webhook' + }, + 'action': { + 'event': 'test_success', + 'event_data_template': { + 'hello': 'yo {{ trigger.query.hello }}', + } + } + } + }) + + client = await aiohttp_client(hass.http.app) + + await client.post('/api/webhook/query_webhook?hello=world') + + assert len(events) == 1 + assert events[0].data['hello'] == 'yo world'