1
mirror of https://github.com/home-assistant/core synced 2024-10-10 12:28:01 +02:00

deCONZ - Increase bridge discovery robustness in config flow (#26911)

This commit is contained in:
Robert Svensson 2019-09-25 21:50:14 +02:00 committed by GitHub
parent cbbdb95003
commit cff7fd0ef3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 2 deletions

View File

@ -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:

View File

@ -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()