Skip to content

Log Withings webhook URL warning only once#164551

Open
ptarjan wants to merge 1 commit intohome-assistant:devfrom
ptarjan:withings-webhook-warning-once
Open

Log Withings webhook URL warning only once#164551
ptarjan wants to merge 1 commit intohome-assistant:devfrom
ptarjan:withings-webhook-warning-once

Conversation

@ptarjan
Copy link
Contributor

@ptarjan ptarjan commented Mar 2, 2026

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_webhook call, 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_invalid flag to WithingsWebhookManager so the warning is only logged once per config entry lifecycle. Subsequent calls to register_webhook with the same invalid URL silently return without re-logging.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:
  • Link to developer documentation pull request:
  • Link to frontend pull request:

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 2, 2026 03:14
@ptarjan ptarjan requested a review from joostlek as a code owner March 2, 2026 03:14
@home-assistant
Copy link

home-assistant bot commented Mar 2, 2026

Hey there @joostlek, mind taking a look at this pull request as it has been labeled with an integration (withings) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of withings can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign withings Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_invalid flag to WithingsWebhookManager to prevent repeated warning logs on subsequent register_webhook calls 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_subscription is patched to always return True, so register_webhook will use _async_cloudhook_generate_url and will not call webhook_generate_url. The extra patch for homeassistant.components.withings.webhook_generate_url looks 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"),
    ):
Comment on lines 263 to 270
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
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment