mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Catch AuthRequired exception in confirm discovery step for Shelly config flow (#46135)
This commit is contained in:
parent
8f19d041e4
commit
b645b151f9
@ -192,6 +192,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
device_info = await validate_input(self.hass, self.host, {})
|
device_info = await validate_input(self.hass, self.host, {})
|
||||||
except HTTP_CONNECT_ERRORS:
|
except HTTP_CONNECT_ERRORS:
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
|
except aioshelly.AuthRequired:
|
||||||
|
return await self.async_step_credentials()
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.exception("Unexpected exception")
|
_LOGGER.exception("Unexpected exception")
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
@ -512,6 +512,36 @@ async def test_zeroconf_confirm_error(hass, error):
|
|||||||
assert result2["errors"] == {"base": base_error}
|
assert result2["errors"] == {"base": base_error}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_zeroconf_confirm_auth_error(hass):
|
||||||
|
"""Test we get credentials form after an auth error when confirming discovery."""
|
||||||
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"aioshelly.get_info",
|
||||||
|
return_value={"mac": "test-mac", "type": "SHSW-1", "auth": False},
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN,
|
||||||
|
data=DISCOVERY_INFO,
|
||||||
|
context={"source": config_entries.SOURCE_ZEROCONF},
|
||||||
|
)
|
||||||
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
|
assert result["errors"] == {}
|
||||||
|
|
||||||
|
with patch(
|
||||||
|
"aioshelly.Device.create",
|
||||||
|
new=AsyncMock(side_effect=aioshelly.AuthRequired),
|
||||||
|
):
|
||||||
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
result["flow_id"],
|
||||||
|
{},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
|
assert result2["step_id"] == "credentials"
|
||||||
|
assert result2["errors"] == {}
|
||||||
|
|
||||||
|
|
||||||
async def test_zeroconf_already_configured(hass):
|
async def test_zeroconf_already_configured(hass):
|
||||||
"""Test we get the form."""
|
"""Test we get the form."""
|
||||||
await setup.async_setup_component(hass, "persistent_notification", {})
|
await setup.async_setup_component(hass, "persistent_notification", {})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user