diff --git a/homeassistant/components/shelly/config_flow.py b/homeassistant/components/shelly/config_flow.py index 38d30fd0b623..c2c80b48fc04 100644 --- a/homeassistant/components/shelly/config_flow.py +++ b/homeassistant/components/shelly/config_flow.py @@ -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: diff --git a/tests/components/shelly/test_config_flow.py b/tests/components/shelly/test_config_flow.py index b7083cb68056..a761fe7836e3 100644 --- a/tests/components/shelly/test_config_flow.py +++ b/tests/components/shelly/test_config_flow.py @@ -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"