mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Catch Reolink LoginFirmwareError (#128590)
This commit is contained in:
parent
201aab9f73
commit
175a87f948
@ -7,7 +7,12 @@ import logging
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from reolink_aio.api import ALLOWED_SPECIAL_CHARS
|
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
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
@ -233,6 +238,15 @@ class ReolinkFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
placeholders["special_chars"] = ALLOWED_SPECIAL_CHARS
|
placeholders["special_chars"] = ALLOWED_SPECIAL_CHARS
|
||||||
except CredentialsInvalidError:
|
except CredentialsInvalidError:
|
||||||
errors[CONF_PASSWORD] = "invalid_auth"
|
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:
|
except ApiError as err:
|
||||||
placeholders["error"] = str(err)
|
placeholders["error"] = str(err)
|
||||||
errors[CONF_HOST] = "api_error"
|
errors[CONF_HOST] = "api_error"
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
"not_admin": "User needs to be admin, user \"{username}\" has authorisation level \"{userlevel}\"",
|
"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}",
|
"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%]",
|
"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}"
|
"webhook_exception": "Home Assistant URL is not available, go to Settings > System > Network > Home Assistant URL and correct the URLs, see {more_info}"
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
@ -7,7 +7,12 @@ from unittest.mock import ANY, AsyncMock, MagicMock, call
|
|||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from freezegun.api import FrozenDateTimeFactory
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
import pytest
|
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 import config_entries
|
||||||
from homeassistant.components import dhcp
|
from homeassistant.components import dhcp
|
||||||
@ -171,6 +176,20 @@ async def test_config_flow_errors(
|
|||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
assert result["errors"] == {CONF_PASSWORD: "invalid_auth"}
|
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
|
reolink_connect.valid_password.return_value = False
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user