Support IPv6 and hostname addressed devices for UPnP eventing - #21
Open
markfrancisonly wants to merge 1 commit into
Open
Support IPv6 and hostname addressed devices for UPnP eventing#21markfrancisonly wants to merge 1 commit into
markfrancisonly wants to merge 1 commit into
Conversation
The notify server port came from int(device_ip.split(".")[-1]), which assumes
the device address is IPv4. An IPv6 address raises ValueError, and so does a
hostname such as wiim.local, since "5" and "local" are not the last octet of
anything. The broad except around the block turns that into a warning and
leaves _notify_server as None, so the device stays usable but never receives a
UPnP event again.
Take the last byte of the parsed address instead, which is the same value for
IPv4 and keeps the existing port assignment unchanged, and fall back to 0 when
the host is a name rather than a literal address.
Bind the wildcard that matches the device family as well: an IPv6 device
reached through a v4 wildcard socket cannot deliver a callback.
markfrancisonly
marked this pull request as ready for review
July 30, 2026 16:43
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this enables: a WiiM device reached over IPv6 can receive UPnP events. Today it cannot — and neither can a device addressed by hostname rather than a literal IP. In both cases eventing is silently disabled, so the device reports no title, artist or artwork and its transport state never updates, while otherwise appearing to work.
Why it fails today
The notify server port is derived from the device address, assuming an IPv4 literal:
Two hosts it cannot parse:
int("2001:db8::5")raisesValueErrorwiim.local—int("local")raisesValueErrorip_addresscomes fromurlparse(device_url).hostname, so either reaches this line. The broadexcept Exceptionaround the block catches theValueError, logsEventing will be disabledand leaves_notify_serverasNone. Nothing else surfaces the failure.Reported as
Device initialisation fails when UPnP device URL contains a hostname #11 — the SDK-side issue for exactly this: direct instantiation with a hostname in the device URL.
WIIM integration: Using a hostname instead of IP address breaks state updates home-assistant/core#168047 — the downstream report, carrying this traceback verbatim:
The integration builds
WiimDevicestraight from the user-provided host, so any hostname config lands here. The issue asks for the fix upstream in this library rather than resolving the hostname in the integration.Fixes #11.
What changes
0.0.0.0socket cannot deliver a callback.Nothing else on the SDK side needs to change:
AiohttpNotifyServeralready brackets the callback URL when the listen address is v6, and the existing 256-port retry is untouched and still applies.Testing
Parametrised over IPv4, IPv6 and a hostname, asserting the source tuple handed to
AiohttpNotifyServer. They fail on currentmainwith the twoValueErrors above.Not verified against a real IPv6 device — I have no IPv6 segment to test on, so the hardware path is unproven.
Not fixed by this
home-assistant/core#177517 is a separate failure with the same symptom — eventing silently dead, no metadata — but it is not this bug. There the address parses fine; the callback host advertised to the device is simply unreachable, because
get_urlfalls back to the first enabled adapter when the routed source address is not itself an enabled adapter. That is a core-side fix (home-assistant/core#177667), not an SDK one. Flagging it so the two aren't conflated: applying this PR will not resolve that report.