From 087bf875d6103f46b7ad7e397a8fd09b7727b1ad Mon Sep 17 00:00:00 2001 From: Simone Chemelli Date: Sat, 26 Sep 2026 22:05:06 +0200 Subject: [PATCH] Cleanup is_hostname in Shelly (#183233) --- homeassistant/components/shelly/config_flow.py | 4 ++-- homeassistant/components/shelly/utils.py | 9 --------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index e3ebcf309a93..9ee8622547dd 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -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) diff --git a/homeassistant/components/shelly/utils.py b/homeassistant/components/shelly/utils.py index 82494b237e63..385c2ab80b04 100644 --- a/homeassistant/components/shelly/utils.py +++ b/homeassistant/components/shelly/utils.py @@ -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: