Fix configuration_url
for Shelly device using IPv6 (#121939)
Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
9f53d0ccd9
commit
50751574b4
3 changed files with 34 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from ipaddress import IPv4Address
|
||||
from ipaddress import IPv4Address, IPv6Address, ip_address
|
||||
import re
|
||||
from types import MappingProxyType
|
||||
from typing import Any, cast
|
||||
|
@ -486,6 +486,20 @@ def get_http_port(data: MappingProxyType[str, Any]) -> int:
|
|||
return cast(int, data.get(CONF_PORT, DEFAULT_HTTP_PORT))
|
||||
|
||||
|
||||
def get_host(host: str) -> str:
|
||||
"""Get the device IP address or hostname."""
|
||||
try:
|
||||
ip_object = ip_address(host)
|
||||
except ValueError:
|
||||
# host contains hostname
|
||||
return host
|
||||
|
||||
if isinstance(ip_object, IPv6Address):
|
||||
return f"[{host}]"
|
||||
|
||||
return host
|
||||
|
||||
|
||||
@callback
|
||||
def async_remove_shelly_rpc_entities(
|
||||
hass: HomeAssistant, domain: str, mac: str, keys: list[str]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue