Skip to content

Commit 4f84e69

Browse files
RaHehl${localEnv}
andauthored
fix: allow DNS hostnames with override_connection_host (#679) (#680)
The IPv6 support commit (958f139) changed ip_from_host() to async, but replaced it with ip_address() in __init__ which doesn't resolve DNS hostnames. This caused a ValueError when using hostnames like 'unifi.local' with override_connection_host=True. Fix: Simply store the host string as-is. The format_host_for_url() function already handles both IP addresses and hostnames correctly. Co-authored-by: ${localEnv} <${localEnv@localhost}>
1 parent b9b542a commit 4f84e69

File tree

2 files changed

+12
-27
lines changed

2 files changed

+12
-27
lines changed

src/uiprotect/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ def __init__(
10751075
self._update_lock = asyncio.Lock()
10761076

10771077
if override_connection_host:
1078-
self._connection_host = ip_address(self._host)
1078+
self._connection_host = self._host
10791079

10801080
if debug:
10811081
set_debug()

tests/test_api.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,17 @@ def test_connection_host_with_hostname_fallback(protect_client: ProtectApiClient
321321

322322

323323
@pytest.mark.parametrize(
324-
("host", "expected_type", "expected_value"),
324+
("host",),
325325
[
326-
("127.0.0.1", IPv4Address, IPv4Address("127.0.0.1")),
327-
("2001:db8::1", IPv6Address, IPv6Address("2001:db8::1")),
328-
("192.168.1.100", IPv4Address, IPv4Address("192.168.1.100")),
329-
("fe80::1", IPv6Address, IPv6Address("fe80::1")),
326+
("127.0.0.1",),
327+
("2001:db8::1",),
328+
("192.168.1.100",),
329+
("fe80::1",),
330+
("unifi.local",),
330331
],
331332
)
332-
def test_connection_host_override(
333-
host: str, expected_type: type, expected_value: IPv4Address | IPv6Address
334-
):
335-
"""Test override_connection_host with various IP addresses."""
333+
def test_connection_host_override(host: str):
334+
"""Test override_connection_host stores host as-is (string)."""
336335
protect = ProtectApiClient(
337336
host,
338337
443,
@@ -342,23 +341,9 @@ def test_connection_host_override(
342341
store_sessions=False,
343342
)
344343

345-
assert protect._connection_host == expected_value
346-
assert isinstance(protect._connection_host, expected_type)
347-
348-
349-
def test_connection_host_override_hostname_fails():
350-
"""Test that override_connection_host with hostname raises ValueError."""
351-
with pytest.raises(
352-
ValueError, match="does not appear to be an IPv4 or IPv6 address"
353-
):
354-
ProtectApiClient(
355-
"unifi.local",
356-
443,
357-
"test",
358-
"test",
359-
override_connection_host=True,
360-
store_sessions=False,
361-
)
344+
# Host is always stored as string, format_host_for_url handles formatting
345+
assert protect._connection_host == host
346+
assert isinstance(protect._connection_host, str)
362347

363348

364349
@pytest.mark.asyncio()

0 commit comments

Comments
 (0)