deCONZ - Increase bridge discovery robustness in config flow (#26911)
This commit is contained in:
parent
cbbdb95003
commit
cff7fd0ef3
2 changed files with 35 additions and 2 deletions
|
@ -90,7 +90,7 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
with async_timeout.timeout(10):
|
with async_timeout.timeout(10):
|
||||||
self.bridges = await async_discovery(session)
|
self.bridges = await async_discovery(session)
|
||||||
|
|
||||||
except asyncio.TimeoutError:
|
except (asyncio.TimeoutError, ResponseError):
|
||||||
self.bridges = []
|
self.bridges = []
|
||||||
|
|
||||||
if len(self.bridges) == 1:
|
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"
|
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."""
|
"""Test config flow with manual input."""
|
||||||
aioclient_mock.get(
|
aioclient_mock.get(
|
||||||
pydeconz.utils.URL_DISCOVER,
|
pydeconz.utils.URL_DISCOVER,
|
||||||
|
@ -148,6 +150,7 @@ async def test_user_step_manual_configuration(hass, aioclient_mock):
|
||||||
|
|
||||||
assert result["type"] == "form"
|
assert result["type"] == "form"
|
||||||
assert result["step_id"] == "init"
|
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 = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"],
|
result["flow_id"],
|
||||||
|
@ -158,6 +161,36 @@ async def test_user_step_manual_configuration(hass, aioclient_mock):
|
||||||
assert result["step_id"] == "link"
|
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):
|
async def test_link_no_api_key(hass):
|
||||||
"""Test config flow should abort if no API key was possible to retrieve."""
|
"""Test config flow should abort if no API key was possible to retrieve."""
|
||||||
flow = config_flow.DeconzFlowHandler()
|
flow = config_flow.DeconzFlowHandler()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue