Add missing brackets to ESPHome configuration URLs with IPv6 addresses (#137132)

fixes #137125
This commit is contained in:
J. Nick Koston 2025-02-01 20:02:10 -06:00 committed by GitHub
parent 27f89f7710
commit 39a575dd29
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 1 deletions

View File

@ -573,7 +573,9 @@ def _async_setup_device_registry(
configuration_url = None
if device_info.webserver_port > 0:
configuration_url = f"http://{entry.data['host']}:{device_info.webserver_port}"
entry_host = entry.data["host"]
host = f"[{entry_host}]" if ":" in entry_host else entry_host
configuration_url = f"http://{host}:{device_info.webserver_port}"
elif (
(dashboard := async_get_dashboard(hass))
and dashboard.data

View File

@ -1100,6 +1100,42 @@ async def test_esphome_device_with_web_server(
assert dev.configuration_url == "http://test.local:80"
async def test_esphome_device_with_ipv6_web_server(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,
mock_client: APIClient,
mock_esphome_device: Callable[
[APIClient, list[EntityInfo], list[UserService], list[EntityState]],
Awaitable[MockESPHomeDevice],
],
) -> None:
"""Test a device with a web server."""
entry = MockConfigEntry(
domain=DOMAIN,
data={
CONF_HOST: "fe80::1",
CONF_PORT: 6053,
CONF_PASSWORD: "",
},
options={},
)
entry.add_to_hass(hass)
device = await mock_esphome_device(
mock_client=mock_client,
entry=entry,
entity_info=[],
user_service=[],
device_info={"webserver_port": 80},
states=[],
)
await hass.async_block_till_done()
entry = device.entry
dev = device_registry.async_get_device(
connections={(dr.CONNECTION_NETWORK_MAC, entry.unique_id)}
)
assert dev.configuration_url == "http://[fe80::1]:80"
async def test_esphome_device_with_compilation_time(
hass: HomeAssistant,
device_registry: dr.DeviceRegistry,