mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
deCONZ - Increase bridge discovery robustness in config flow (#26911)
This commit is contained in:
parent
cbbdb95003
commit
cff7fd0ef3
@ -90,7 +90,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
with async_timeout.timeout(10):
|
||||
self.bridges = await async_discovery(session)
|
||||
|
||||
except asyncio.TimeoutError:
|
||||
except (asyncio.TimeoutError, ResponseError):
|
||||
self.bridges = []
|
||||
|
||||
if len(self.bridges) == 1:
|
||||
|
@ -134,7 +134,9 @@ async def test_user_step_two_bridges_selection(hass, aioclient_mock):
|
||||
assert flow.deconz_config[config_flow.CONF_HOST] == "1.2.3.4"
|
||||
|
||||
|
||||
async def test_user_step_manual_configuration(hass, aioclient_mock):
|
||||
async def test_user_step_manual_configuration_no_bridges_discovered(
|
||||
hass, aioclient_mock
|
||||
):
|
||||
"""Test config flow with manual input."""
|
||||
aioclient_mock.get(
|
||||
pydeconz.utils.URL_DISCOVER,
|
||||
@ -148,6 +150,7 @@ async def test_user_step_manual_configuration(hass, aioclient_mock):
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "init"
|
||||
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
@ -158,6 +161,36 @@ async def test_user_step_manual_configuration(hass, aioclient_mock):
|
||||
assert result["step_id"] == "link"
|
||||
|
||||
|
||||
async def test_user_step_manual_configuration_after_timeout(hass):
|
||||
"""Test config flow with manual input."""
|
||||
with patch(
|
||||
"homeassistant.components.deconz.config_flow.async_discovery",
|
||||
side_effect=asyncio.TimeoutError,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN, context={"source": "user"}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "init"
|
||||
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
||||
|
||||
|
||||
async def test_user_step_manual_configuration_after_ResponseError(hass):
|
||||
"""Test config flow with manual input."""
|
||||
with patch(
|
||||
"homeassistant.components.deconz.config_flow.async_discovery",
|
||||
side_effect=config_flow.ResponseError,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
config_flow.DOMAIN, context={"source": "user"}
|
||||
)
|
||||
|
||||
assert result["type"] == "form"
|
||||
assert result["step_id"] == "init"
|
||||
assert not hass.config_entries.flow._progress[result["flow_id"]].bridges
|
||||
|
||||
|
||||
async def test_link_no_api_key(hass):
|
||||
"""Test config flow should abort if no API key was possible to retrieve."""
|
||||
flow = config_flow.DeconzFlowHandler()
|
||||
|
Loading…
x
Reference in New Issue
Block a user