diff --git a/homeassistant/components/nibe_heatpump/config_flow.py b/homeassistant/components/nibe_heatpump/config_flow.py index ba3325d9daf46..bd48583547c07 100644 --- a/homeassistant/components/nibe_heatpump/config_flow.py +++ b/homeassistant/components/nibe_heatpump/config_flow.py @@ -2,6 +2,7 @@ from __future__ import annotations import errno +from socket import gaierror from typing import Any from nibe.connection.nibegw import NibeGW @@ -14,7 +15,6 @@ from homeassistant.core import HomeAssistant from homeassistant.data_entry_flow import FlowResult from homeassistant.helpers import config_validation as cv -from homeassistant.util.network import is_ipv4_address from .const import ( CONF_CONNECTION_TYPE, @@ -51,9 +51,6 @@ def __init__(self, message: str, field: str, error: str) -> None: async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, Any]: """Validate the user input allows us to connect.""" - if not is_ipv4_address(data[CONF_IP_ADDRESS]): - raise FieldError("Not a valid ipv4 address", CONF_IP_ADDRESS, "address") - heatpump = HeatPump(Model[data[CONF_MODEL]]) heatpump.initialize() @@ -79,6 +76,8 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> dict[str, coil = await connection.read_coil(coil) word_swap = coil.value == "ON" coil = await connection.write_coil(coil) + except gaierror as exception: + raise FieldError(str(exception), "ip_address", "address") from exception except CoilNotFoundException as exception: raise FieldError( "Model selected doesn't seem to support expected coils", "base", "model" diff --git a/homeassistant/components/nibe_heatpump/strings.json b/homeassistant/components/nibe_heatpump/strings.json index 45e55b61083d2..9bbee6ae2eeb8 100644 --- a/homeassistant/components/nibe_heatpump/strings.json +++ b/homeassistant/components/nibe_heatpump/strings.json @@ -3,7 +3,7 @@ "step": { "user": { "data": { - "ip_address": "Remote IP address", + "ip_address": "Remote address", "remote_read_port": "Remote read port", "remote_write_port": "Remote write port", "listening_port": "Local listening port" @@ -13,7 +13,7 @@ "error": { "write": "Error on write request to pump. Verify your `Remote write port` or `Remote IP address`.", "read": "Error on read request from pump. Verify your `Remote read port` or `Remote IP address`.", - "address": "Invalid remote IP address specified. Address must be a IPV4 address.", + "address": "Invalid remote address specified. Address must be an IP address or a resolvable hostname.", "address_in_use": "The selected listening port is already in use on this system.", "model": "The model selected doesn't seem to support modbus40", "unknown": "[%key:common::config_flow::error::unknown%]" diff --git a/homeassistant/components/nibe_heatpump/translations/en.json b/homeassistant/components/nibe_heatpump/translations/en.json index 74dd8313e95cc..3837989511f40 100644 --- a/homeassistant/components/nibe_heatpump/translations/en.json +++ b/homeassistant/components/nibe_heatpump/translations/en.json @@ -1,10 +1,7 @@ { "config": { - "abort": { - "already_configured": "Device is already configured" - }, "error": { - "address": "Invalid remote IP address specified. Address must be a IPV4 address.", + "address": "Invalid remote address specified. Address must be an IP address or a resolvable hostname.", "address_in_use": "The selected listening port is already in use on this system.", "model": "The model selected doesn't seem to support modbus40", "read": "Error on read request from pump. Verify your `Remote read port` or `Remote IP address`.", @@ -14,7 +11,7 @@ "step": { "user": { "data": { - "ip_address": "Remote IP address", + "ip_address": "Remote address", "listening_port": "Local listening port", "remote_read_port": "Remote read port", "remote_write_port": "Remote write port" diff --git a/tests/components/nibe_heatpump/test_config_flow.py b/tests/components/nibe_heatpump/test_config_flow.py index 2647102ba5ae1..f7dc08c41bbf4 100644 --- a/tests/components/nibe_heatpump/test_config_flow.py +++ b/tests/components/nibe_heatpump/test_config_flow.py @@ -1,5 +1,6 @@ """Test the Nibe Heat Pump config flow.""" import errno +from socket import gaierror from unittest.mock import Mock, patch from nibe.coil import Coil @@ -150,13 +151,13 @@ async def test_unexpected_exception(hass: HomeAssistant, mock_connection: Mock) assert result2["errors"] == {"base": "unknown"} -async def test_invalid_ip(hass: HomeAssistant, mock_connection: Mock) -> None: +async def test_invalid_host(hass: HomeAssistant, mock_connection: Mock) -> None: """Test we handle cannot connect error.""" result = await hass.config_entries.flow.async_init( DOMAIN, context={"source": config_entries.SOURCE_USER} ) - mock_connection.return_value.read_coil.side_effect = Exception() + mock_connection.return_value.read_coil.side_effect = gaierror() result2 = await hass.config_entries.flow.async_configure( result["flow_id"], {**MOCK_FLOW_USERDATA, "ip_address": "abcd"}