diff --git a/homeassistant/components/reolink/config_flow.py b/homeassistant/components/reolink/config_flow.py index bf58646536f..102aeae575e 100644 --- a/homeassistant/components/reolink/config_flow.py +++ b/homeassistant/components/reolink/config_flow.py @@ -7,7 +7,12 @@ import logging from typing import Any from reolink_aio.api import ALLOWED_SPECIAL_CHARS -from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError +from reolink_aio.exceptions import ( + ApiError, + CredentialsInvalidError, + LoginFirmwareError, + ReolinkError, +) import voluptuous as vol from homeassistant.components import dhcp @@ -233,6 +238,15 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN): placeholders["special_chars"] = ALLOWED_SPECIAL_CHARS except CredentialsInvalidError: errors[CONF_PASSWORD] = "invalid_auth" + except LoginFirmwareError: + errors["base"] = "update_needed" + placeholders["current_firmware"] = host.api.sw_version + placeholders["needed_firmware"] = ( + host.api.sw_version_required.version_string + ) + placeholders["download_center_url"] = ( + "https://reolink.com/download-center" + ) except ApiError as err: placeholders["error"] = str(err) errors[CONF_HOST] = "api_error" diff --git a/homeassistant/components/reolink/strings.json b/homeassistant/components/reolink/strings.json index 4ec4dcffdfd..67fd5329e14 100644 --- a/homeassistant/components/reolink/strings.json +++ b/homeassistant/components/reolink/strings.json @@ -31,6 +31,7 @@ "not_admin": "User needs to be admin, user \"{username}\" has authorisation level \"{userlevel}\"", "password_incompatible": "Password contains incompatible special character, only these characters are allowed: a-z, A-Z, 0-9 or {special_chars}", "unknown": "[%key:common::config_flow::error::unknown%]", + "update_needed": "Failed to login because of outdated firmware, please update the firmware to version {needed_firmware} using the Reolink Download Center: {download_center_url}, currently version {current_firmware} is installed", "webhook_exception": "Home Assistant URL is not available, go to Settings > System > Network > Home Assistant URL and correct the URLs, see {more_info}" }, "abort": { diff --git a/tests/components/reolink/test_config_flow.py b/tests/components/reolink/test_config_flow.py index 9382d9f7901..bb896428b99 100644 --- a/tests/components/reolink/test_config_flow.py +++ b/tests/components/reolink/test_config_flow.py @@ -7,7 +7,12 @@ from unittest.mock import ANY, AsyncMock, MagicMock, call from aiohttp import ClientSession from freezegun.api import FrozenDateTimeFactory import pytest -from reolink_aio.exceptions import ApiError, CredentialsInvalidError, ReolinkError +from reolink_aio.exceptions import ( + ApiError, + CredentialsInvalidError, + LoginFirmwareError, + ReolinkError, +) from homeassistant import config_entries from homeassistant.components import dhcp @@ -171,6 +176,20 @@ async def test_config_flow_errors( assert result["step_id"] == "user" assert result["errors"] == {CONF_PASSWORD: "invalid_auth"} + reolink_connect.get_host_data.side_effect = LoginFirmwareError("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 FlowResultType.FORM + assert result["step_id"] == "user" + assert result["errors"] == {"base": "update_needed"} + reolink_connect.valid_password.return_value = False result = await hass.config_entries.flow.async_configure( result["flow_id"],