mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add missing error catch in Shelly reauth flow (#79205)
This commit is contained in:
parent
8c0e3b9d50
commit
8719829fbe
@ -278,7 +278,15 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
host = self.entry.data[CONF_HOST]
|
host = self.entry.data[CONF_HOST]
|
||||||
|
|
||||||
if user_input is not None:
|
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:
|
if self.entry.data.get("gen", 1) != 1:
|
||||||
user_input[CONF_USERNAME] = "admin"
|
user_input[CONF_USERNAME] = "admin"
|
||||||
try:
|
try:
|
||||||
|
@ -885,3 +885,40 @@ async def test_reauth_unsuccessful(hass, test_data):
|
|||||||
|
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
||||||
assert result["reason"] == "reauth_unsuccessful"
|
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user