Repository navigation
Wrap IPv6 hosts in brackets in request URLs - #646
Merged
Merged
Conversation
The v1 and v2 clients built URLs as http://{host}/... and
https://{host}..., so an IPv6 address like 2001:db8::1 produced an
invalid URL. aiohttp then raised InvalidUrlClientError, which surfaced
as a RequestError. Add a _url_host property that brackets IPv6 literals
and use it for both API versions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 of 22 tasks
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #646 +/- ##
=======================================
Coverage 99.32% 99.33%
=======================================
Files 9 9
Lines 741 751 +10
Branches 78 79 +1
=======================================
+ Hits 736 746 +10
Misses 2 2
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
nvanofwegen
approved these changes
Dec 1, 2026
7 of 22 tasks
24 tasks done
5 of 22 tasks
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.
The v1 and v2 clients build their request URLs as
http://{host}/{path}andhttps://{host}{path}. When the host is an IPv6 address, that gives a URL likehttp://2001:db8::1/api, which isn't valid: aiohttp reads everything after the first colon as a port and raisesInvalidUrlClientError. That's aClientError, so callers only see the genericRequestError"Error occurred while communicating with the HomeWizard Energy device".Home Assistant runs into this when zeroconf saves a P1 Meter's IPv6 address as the configured host: home-assistant/core#178629.
What changes
_url_host: a new property on the base class that wraps IPv6 addresses in brackets (RFC 3986) and returns IPv4 addresses and hostnames unchanged. The publichostproperty still returns the address as given._url_host._get_v2_product_idalready put brackets around IPv6 in itsHostheader, so it's unchanged.Tests
_url_hostfor IPv4, hostnames,.localnames and IPv6 addresses.http://[2001:db8::1]/api/v1/dataandhttps://[2001:db8::1]/api.InvalidUrlClientErrorand accepts the bracketed one. I couldn't run it against a real device over IPv6.🤖 Generated with Claude Code