From 572b1ffc0f63fcf7b92f1a903a7864c4bc8baa27 Mon Sep 17 00:00:00 2001 From: Paul Tarjan Date: Thu, 11 Dec 2025 21:04:32 +0000 Subject: [PATCH] Improve Withings webhook error messages with docs link Split the webhook registration error into two specific messages: - One for missing HTTPS - One for wrong port (not 443) This helps users understand exactly what needs to be fixed. Both messages include a link to the integration documentation. --- homeassistant/components/withings/__init__.py | 12 +++++++++--- tests/components/withings/test_init.py | 11 +++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/withings/__init__.py b/homeassistant/components/withings/__init__.py index 9338c28da1cfd..bea4af3627abb 100644 --- a/homeassistant/components/withings/__init__.py +++ b/homeassistant/components/withings/__init__.py @@ -259,10 +259,16 @@ async def register_webhook( self.hass, self.entry.data[CONF_WEBHOOK_ID] ) url = URL(webhook_url) - if url.scheme != "https" or url.port != 443: + if url.scheme != "https": LOGGER.warning( - "Webhook not registered - " - "https and port 443 is required to register the webhook" + "Webhook not registered - HTTPS is required. " + "See https://www.home-assistant.io/integrations/withings/#webhook-requirements" + ) + return + if url.port != 443: + LOGGER.warning( + "Webhook not registered - port 443 is required. " + "See https://www.home-assistant.io/integrations/withings/#webhook-requirements" ) return diff --git a/tests/components/withings/test_init.py b/tests/components/withings/test_init.py index 86c4f1d8cbb9e..b5035df7afedc 100644 --- a/tests/components/withings/test_init.py +++ b/tests/components/withings/test_init.py @@ -348,7 +348,13 @@ async def test_setup_with_cloud( assert not hass.config_entries.async_entries(DOMAIN) -@pytest.mark.parametrize("url", ["http://example.com", "https://example.com:444"]) +@pytest.mark.parametrize( + ("url", "expected_message"), + [ + ("http://example.com", "HTTPS is required"), + ("https://example.com:444", "port 443 is required"), + ], +) async def test_setup_no_webhook( hass: HomeAssistant, webhook_config_entry: MockConfigEntry, @@ -356,6 +362,7 @@ async def test_setup_no_webhook( caplog: pytest.LogCaptureFixture, freezer: FrozenDateTimeFactory, url: str, + expected_message: str, ) -> None: """Test if set up with cloud link and without https.""" hass.config.components.add("cloud") @@ -378,7 +385,7 @@ async def test_setup_no_webhook( await hass.async_block_till_done() mock_async_generate_url.assert_called_once() - assert "https and port 443 is required to register the webhook" in caplog.text + assert expected_message in caplog.text async def test_cloud_disconnect(