diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 548d230f325..9084d80e5c5 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -10,7 +10,7 @@ import contextlib from datetime import timedelta from typing import Any -from aiohttp.hdrs import METH_HEAD, METH_POST +from aiohttp.hdrs import METH_POST from aiohttp.web import Request, Response from aiowithings import NotificationCategory, WithingsClient from aiowithings.util import to_enum @@ -198,6 +198,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: webhook_name, entry.data[CONF_WEBHOOK_ID], get_webhook_handler(coordinators), + allowed_methods=[METH_POST], ) await async_subscribe_webhooks(client, webhook_url) @@ -325,14 +326,6 @@ def get_webhook_handler( async def async_webhook_handler( hass: HomeAssistant, webhook_id: str, request: Request ) -> Response | None: - # Handle http head calls to the path. - # When creating a notify subscription, Withings will check that the endpoint is running by sending a HEAD request. - if request.method == METH_HEAD: - return Response() - - if request.method != METH_POST: - return json_message_response("Invalid method", message_code=2) - # Handle http post calls to the path. if not request.body_exists: return json_message_response("No request body", message_code=12) diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index 9418b032a02..baec7e92ea0 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -4,6 +4,7 @@ from typing import Any from unittest.mock import AsyncMock, MagicMock, patch from urllib.parse import urlparse +from aiohttp.hdrs import METH_HEAD from aiowithings import ( NotificationCategory, WithingsAuthenticationFailedError, @@ -173,27 +174,19 @@ async def test_webhook_subscription_polling_config( assert withings.list_notification_configurations.call_count == 0 -@pytest.mark.parametrize( - "method", - [ - "PUT", - "HEAD", - ], -) -async def test_requests( +async def test_head_request( hass: HomeAssistant, withings: AsyncMock, webhook_config_entry: MockConfigEntry, hass_client_no_auth: ClientSessionGenerator, - method: str, ) -> None: - """Test we handle request methods Withings sends.""" + """Test we handle head requests Withings sends.""" await setup_integration(hass, webhook_config_entry) client = await hass_client_no_auth() webhook_url = async_generate_url(hass, WEBHOOK_ID) response = await client.request( - method=method, + method=METH_HEAD, path=urlparse(webhook_url).path, ) assert response.status == 200