diff --git a/homeassistant/components/reolink/config_flow.py b/homeassistant/components/reolink/config_flow.py index 75ad26665c3..d24fd8d1f14 100644 --- a/homeassistant/components/reolink/config_flow.py +++ b/homeassistant/components/reolink/config_flow.py @@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv from homeassistant.helpers.device_registry import format_mac from .const import CONF_PROTOCOL, CONF_USE_HTTPS, DOMAIN -from .exceptions import ReolinkException, UserNotAdmin +from .exceptions import ReolinkException, ReolinkWebhookException, UserNotAdmin from .host import ReolinkHost _LOGGER = logging.getLogger(__name__) @@ -133,6 +133,12 @@ class ReolinkFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): except ApiError as err: placeholders["error"] = str(err) errors[CONF_HOST] = "api_error" + except ReolinkWebhookException as err: + placeholders["error"] = str(err) + placeholders[ + "more_info" + ] = "https://www.home-assistant.io/more-info/no-url-available/#configuring-the-instance-url" + errors["base"] = "webhook_exception" except (ReolinkError, ReolinkException) as err: placeholders["error"] = str(err) errors[CONF_HOST] = "cannot_connect" diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 7d8c3a213eb..2389c433b20 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -22,7 +22,8 @@ "cannot_connect": "Failed to connect, check the IP address of the camera", "invalid_auth": "[%key:common::config_flow::error::invalid_auth%]", "not_admin": "User needs to be admin, user ''{username}'' has authorisation level ''{userlevel}''", - "unknown": "[%key:common::config_flow::error::unknown%]" + "unknown": "[%key:common::config_flow::error::unknown%]", + "webhook_exception": "Home Assistant URL is not available, go to Settings > System > Network > Home Assistant URL and correct the URLs, see {more_info}" }, "abort": { "already_configured": "[%key:common::config_flow::abort::already_configured_device%]", diff --git a/tests/components/reolink/test_config_flow.py b/tests/components/reolink/test_config_flow.py index 7d25fd62811..b6e48cab7b2 100644 --- a/tests/components/reolink/test_config_flow.py +++ b/tests/components/reolink/test_config_flow.py @@ -9,6 +9,7 @@ from homeassistant import config_entries, data_entry_flow from homeassistant.components import dhcp from homeassistant.components.reolink import const from homeassistant.components.reolink.config_flow import DEFAULT_PROTOCOL +from homeassistant.components.reolink.exceptions import ReolinkWebhookException from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_PORT, CONF_USERNAME from homeassistant.core import HomeAssistant from homeassistant.helpers.device_registry import format_mac @@ -109,6 +110,20 @@ async def test_config_flow_errors( assert result["step_id"] == "user" assert result["errors"] == {CONF_HOST: "cannot_connect"} + reolink_connect.get_host_data.side_effect = ReolinkWebhookException("Test error") + result = await hass.config_entries.flow.async_configure( + result["flow_id"], + { + CONF_USERNAME: TEST_USERNAME, + CONF_PASSWORD: TEST_PASSWORD, + CONF_HOST: TEST_HOST, + }, + ) + + assert result["type"] is data_entry_flow.FlowResultType.FORM + assert result["step_id"] == "user" + assert result["errors"] == {"base": "webhook_exception"} + reolink_connect.get_host_data.side_effect = json.JSONDecodeError( "test_error", "test", 1 )