Skip to content

Resolve WiiM UPnP event callback host from the route to the device - #177667

Open
markfrancisonly wants to merge 4 commits into
home-assistant:devfrom
markfrancisonly:wiim-route-aware-upnp-callback-host
Open

Resolve WiiM UPnP event callback host from the route to the device#177667
markfrancisonly wants to merge 4 commits into
home-assistant:devfrom
markfrancisonly:wiim-route-aware-upnp-callback-host

Conversation

@markfrancisonly

@markfrancisonly markfrancisonly commented Jul 30, 2026

Copy link
Copy Markdown

Proposed change

The UPnP event callback host was taken from get_url(), which resolves to hass.config.api.local_ip when no internal URL is configured. That value comes from network.async_get_source_ip, which returns all_ipv4s[0] whenever the routed source address is not itself an enabled adapter. The first enabled adapter has no relationship to the route to any given device, so on a multi-homed host it can be an address the device cannot reach.

The GENA subscription still succeeds in that case, so nothing errors and nothing is logged, but no NOTIFY is ever delivered: the media player reports no media_title, media_artist or entity_picture, and its transport state never updates.

This resolves the address per device with async_get_local_ip against the device's own UPnP location, which is what dlna_dmr already does with the same async_upnp_client dependency:

https://github.com/home-assistant/core/blob/dev/homeassistant/components/dlna_dmr/media_player.py#L376-L379

async_setup_entry already builds upnp_location immediately above, so it is a drop-in. The Home Assistant URL is kept as the fallback when the route cannot be resolved, so the existing ConfigEntryNotReady behaviour is unchanged.

Measured on the affected host (3 interfaces, device reachable only via eth2):

enabled adapters old behaviour this PR
eth1 192.168.20.5 (unreachable) 192.168.30.5
eth1, eth2 192.168.30.5 192.168.30.5
eth1, eth0 172.30.33.5 (unreachable) 192.168.30.5

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

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:

The callback host came from get_url(), which resolves to
hass.config.api.local_ip when no internal URL is configured. That value comes
from network.async_get_source_ip, which returns all_ipv4s[0] whenever the
routed source address is not itself an enabled adapter. The first enabled
adapter has no relationship to the route to any given device, and on a
container host it can be an interface the device cannot reach.

The GENA subscription still succeeds in that case, so nothing errors and
nothing is logged, but no NOTIFY is ever delivered: the media player reports no
title, artist or artwork and its transport state never updates.

Resolve the address per device with async_get_local_ip against the device's own
UPnP location, as dlna_dmr already does, keeping the Home Assistant URL as the
fallback when the route cannot be resolved.
Copilot AI review requested due to automatic review settings July 30, 2026 15:59
@home-assistant

Copy link
Copy Markdown
Contributor

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

Code owner commands

Code owners of wiim can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign wiim Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Routes WiiM UPnP callbacks through the interface that reaches each device.

Changes:

  • Resolves callback IPs from device routes with URL fallback.
  • Adds dependency metadata and setup tests.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
homeassistant/components/wiim/__init__.py Uses route-derived callback host.
homeassistant/components/wiim/util.py Adds callback host resolution and fallback.
homeassistant/components/wiim/manifest.json Declares direct UPnP dependency.
requirements_all.txt Records WiiM dependency usage.
tests/components/wiim/conftest.py Mocks route resolution.
tests/components/wiim/test_init.py Tests route lookup and failure handling.

Comment thread homeassistant/components/wiim/util.py
async_get_local_ip returns the family that routes to the device, and
AiohttpNotifyServer brackets IPv6 callback URLs itself, so the resolved address
is used verbatim. Pin that so no address parsing is introduced here later.
Copilot AI review requested due to automatic review settings July 30, 2026 16:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

tests/components/wiim/test_init.py:84

  • Assert that the resolved IP is forwarded to async_create_wiim_device as local_host. This currently verifies only that route lookup occurred, so it would still pass if setup ignored the result and advertised a different callback host.
    mock_local_ip.assert_awaited_once_with(
        "http://192.168.1.100:49152/description.xml", hass.loop
    )

Copilot AI review requested due to automatic review settings July 30, 2026 16:32
@markfrancisonly
markfrancisonly marked this pull request as ready for review July 30, 2026 16:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WiiM advertises an unreachable UPnP event callback host on multi-homed hosts, silently disabling eventing

2 participants