Log Withings webhook URL warning only once#164551
Log Withings webhook URL warning only once#164551ptarjan wants to merge 1 commit intohome-assistant:devfrom
Conversation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Hey there @joostlek, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
This PR reduces log spam in the Withings integration by ensuring the “invalid webhook URL” warning is emitted only once during a config entry lifecycle, even if webhook registration is retried repeatedly due to cloud reconnect/disconnect behavior.
Changes:
- Add a
_webhook_url_invalidflag toWithingsWebhookManagerto prevent repeated warning logs on subsequentregister_webhookcalls when the webhook URL is invalid. - Strengthen/add tests to assert the warning is logged exactly once, including across a simulated cloud disconnect/reconnect.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
homeassistant/components/withings/__init__.py |
Adds state to suppress repeated invalid-webhook warnings during repeated registration attempts. |
tests/components/withings/test_init.py |
Adds assertions and a new test to ensure the warning is logged only once. |
Comments suppressed due to low confidence (1)
tests/components/withings/test_init.py:427
- In this test,
cloud.async_active_subscriptionis patched to always returnTrue, soregister_webhookwill use_async_cloudhook_generate_urland will not callwebhook_generate_url. The extra patch forhomeassistant.components.withings.webhook_generate_urllooks unused and can be removed to keep the test setup minimal and avoid masking unexpected calls.
patch(
"homeassistant.components.cloud.async_delete_cloudhook",
),
patch("homeassistant.components.withings.webhook_generate_url"),
):
| if url.scheme != "https": | ||
| LOGGER.warning( | ||
| "Webhook not registered - HTTPS is required. " | ||
| "See https://www.home-assistant.io/integrations/withings/#webhook-requirements" | ||
| ) | ||
| if not self._webhook_url_invalid: | ||
| LOGGER.warning( | ||
| "Webhook not registered - HTTPS is required. " | ||
| "See https://www.home-assistant.io/integrations/withings/#webhook-requirements" | ||
| ) | ||
| self._webhook_url_invalid = True | ||
| return |
There was a problem hiding this comment.
Using a single _webhook_url_invalid boolean suppresses all future webhook URL warnings for this config entry, even if the invalid condition changes (e.g., first call fails due to HTTP, later calls fail due to non-443 port, or the URL itself changes). That can hide actionable information from the user once the first warning has happened. Consider tracking the last warned condition (e.g., last invalid URL or last invalid reason) and only suppress repeats for the same condition, or reset the flag after a successful registration.
Breaking change
Proposed change
The Withings integration logs a warning when the webhook URL doesn't meet requirements (HTTPS on port 443). Currently, this warning is logged on every
register_webhookcall, which can happen repeatedly due to cloud disconnect/reconnect cycles and retry timers.In my case, running Home Assistant on port 8123 without a cloud subscription, the warning was logging every 5-10 minutes — filling the log with hundreds of identical warnings per day.
This PR adds a
_webhook_url_invalidflag toWithingsWebhookManagerso the warning is only logged once per config entry lifecycle. Subsequent calls toregister_webhookwith the same invalid URL silently return without re-logging.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: