From 47f51601544219d37290d25a1e813cb13a525068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jarek=20=C5=9Awierczy=C5=84ski?= Date: Fri, 14 Apr 2023 09:46:00 +0200 Subject: [PATCH] Allow GET in webhook triggers (#56446) --- homeassistant/components/webhook/__init__.py | 1 + tests/components/webhook/test_init.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/homeassistant/components/webhook/__init__.py b/homeassistant/components/webhook/__init__.py index bd80f38b832..b067321a1c0 100644 --- a/homeassistant/components/webhook/__init__.py +++ b/homeassistant/components/webhook/__init__.py @@ -160,6 +160,7 @@ class WebhookView(HomeAssistantView): head = _handle post = _handle put = _handle + get = _handle @websocket_api.websocket_command( diff --git a/tests/components/webhook/test_init.py b/tests/components/webhook/test_init.py index 56ccbddca56..e9d3d6e38b8 100644 --- a/tests/components/webhook/test_init.py +++ b/tests/components/webhook/test_init.py @@ -131,6 +131,25 @@ async def test_webhook_put(hass: HomeAssistant, mock_client) -> None: assert hooks[0][2].method == "PUT" +async def test_webhook_get(hass, mock_client): + """Test sending a get request to a webhook.""" + hooks = [] + webhook_id = hass.components.webhook.async_generate_id() + + async def handle(*args): + """Handle webhook.""" + hooks.append(args) + + hass.components.webhook.async_register("test", "Test hook", webhook_id, handle) + + resp = await mock_client.get(f"/api/webhook/{webhook_id}") + assert resp.status == 200 + assert len(hooks) == 1 + assert hooks[0][0] is hass + assert hooks[0][1] == webhook_id + assert hooks[0][2].method == "GET" + + async def test_webhook_head(hass: HomeAssistant, mock_client) -> None: """Test sending a head request to a webhook.""" hooks = []