Catch Reolink LoginFirmwareError (#128590)
parent
201aab9f73
commit
175a87f948
|
@ -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"
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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"],
|
||||
|
|
Loading…
Reference in New Issue