Skip to content
Snippets Groups Projects
Unverified Commit 8719829f authored by Maciej Bieniek's avatar Maciej Bieniek Committed by GitHub
Browse files

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

parent 8c0e3b9d
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment