1
mirror of https://github.com/home-assistant/core synced 2024-08-15 18:25:44 +02:00

Add missing error catch in Shelly reauth flow (#79205)

This commit is contained in:
Maciej Bieniek 2022-09-28 15:00:27 +00:00 committed by GitHub
parent 8c0e3b9d50
commit 8719829fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 1 deletions

View File

@ -278,7 +278,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
host = self.entry.data[CONF_HOST]
if user_input is not None:
info = await self._async_get_info(host)
try:
info = await self._async_get_info(host)
except (
asyncio.TimeoutError,
aiohttp.ClientError,
aioshelly.exceptions.FirmwareUnsupported,
):
return self.async_abort(reason="reauth_unsuccessful")
if self.entry.data.get("gen", 1) != 1:
user_input[CONF_USERNAME] = "admin"
try:

View File

@ -885,3 +885,40 @@ async def test_reauth_unsuccessful(hass, test_data):
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "reauth_unsuccessful"
@pytest.mark.parametrize(
"error",
[
asyncio.TimeoutError,
aiohttp.ClientError,
aioshelly.exceptions.FirmwareUnsupported,
],
)
async def test_reauth_get_info_error(hass, error):
"""Test reauthentication flow failed with error in get_info()."""
entry = MockConfigEntry(
domain="shelly", unique_id="test-mac", data={"host": "0.0.0.0", "gen": 2}
)
entry.add_to_hass(hass)
with patch(
"aioshelly.common.get_info",
side_effect=error,
):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_REAUTH, "entry_id": entry.entry_id},
data=entry.data,
)
assert result["type"] == data_entry_flow.FlowResultType.FORM
assert result["step_id"] == "reauth_confirm"
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
user_input={"password": "test2 password"},
)
assert result["type"] == data_entry_flow.FlowResultType.ABORT
assert result["reason"] == "reauth_unsuccessful"