Cleanup is_hostname in Shelly (#183233)

This commit is contained in:
Simone Chemelli
2026-09-26 22:05:06 +02:00
committed by GitHub
parent e34a15c912
commit 087bf875d6
2 changed files with 2 additions and 11 deletions
@@ -69,6 +69,7 @@ from homeassistant.helpers.selector import (
SelectSelectorMode,
)
from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from homeassistant.util.network import is_ip_address
from .ble_provisioning import (
ProvisioningState,
@@ -96,7 +97,6 @@ from .utils import (
get_model_name,
get_rpc_device_wakeup_period,
get_ws_context,
is_hostname,
mac_address_from_name,
)
@@ -722,7 +722,7 @@ class ShellyConfigFlow(ConfigFlow, domain=DOMAIN):
current_entry = await self.async_set_unique_id(mac)
current_host = current_entry.data.get(CONF_HOST) if current_entry else None
# A user-configured hostname must not be replaced by the resolved IP
keep_hostname = current_host is not None and is_hostname(current_host)
keep_hostname = current_host is not None and not is_ip_address(current_host)
if current_entry and (current_host == host or keep_hostname):
LOGGER.debug("async_reconnect_soon: host: %s, mac: %s", host, mac)
await async_reconnect_soon(self.hass, current_entry)
-9
View File
@@ -608,15 +608,6 @@ def get_http_port(data: Mapping[str, Any]) -> int:
return cast(int, data.get(CONF_PORT, DEFAULT_HTTP_PORT))
def is_hostname(host: str) -> bool:
"""Return True if host is a hostname rather than an IP address."""
try:
ip_address(host)
except ValueError:
return True
return False
def get_host(host: str) -> str:
"""Get the device IP address or hostname."""
try: