Abort deCONZ config flow if no radio hardware is connected (#40811)

This commit is contained in:
Robert Svensson 2020-10-01 09:23:12 +02:00 committed by GitHub
parent df1e910ac7
commit 2922d4675f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 0 deletions

View file

@ -172,6 +172,9 @@ class DeconzFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
except asyncio.TimeoutError:
return self.async_abort(reason="no_bridges")
if self.bridge_id == "0000000000000000":
return self.async_abort(reason="no_hardware_available")
return self.async_create_entry(title=self.bridge_id, data=self.deconz_config)
async def async_step_ssdp(self, discovery_info):

View file

@ -29,6 +29,7 @@
"already_configured": "Bridge is already configured",
"already_in_progress": "Config flow for bridge is already in progress.",
"no_bridges": "No deCONZ bridges discovered",
"no_hardware_available": "No radio hardware connected to deCONZ",
"not_deconz_bridge": "Not a deCONZ bridge",
"one_instance_only": "Component only supports one deCONZ instance",
"updated_instance": "Updated deCONZ instance with new host address"

View file

@ -4,6 +4,7 @@
"already_configured": "Bridge is already configured",
"already_in_progress": "Config flow for bridge is already in progress.",
"no_bridges": "No deCONZ bridges discovered",
"no_hardware_available": "No radio hardware connected to deCONZ",
"not_deconz_bridge": "Not a deCONZ bridge",
"one_instance_only": "Component only supports one deCONZ instance",
"updated_instance": "Updated deCONZ instance with new host address"

View file

@ -24,6 +24,8 @@ from .test_gateway import API_KEY, BRIDGEID, setup_deconz_integration
from tests.async_mock import patch
BAD_BRIDGEID = "0000000000000000"
async def test_flow_discovered_bridges(hass, aioclient_mock):
"""Test that config flow works for discovered bridges."""
@ -391,6 +393,35 @@ async def test_flow_ssdp_discovery(hass, aioclient_mock):
}
async def test_flow_ssdp_discovery_bad_bridge_id_aborts(hass, aioclient_mock):
"""Test that config flow aborts if deCONZ signals no radio hardware available."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
data={
ssdp.ATTR_SSDP_LOCATION: "http://1.2.3.4:80/",
ssdp.ATTR_UPNP_MANUFACTURER_URL: DECONZ_MANUFACTURERURL,
ssdp.ATTR_UPNP_SERIAL: BAD_BRIDGEID,
},
context={"source": "ssdp"},
)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result["step_id"] == "link"
aioclient_mock.post(
"http://1.2.3.4:80/api",
json=[{"success": {"username": API_KEY}}],
headers={"content-type": CONTENT_TYPE_JSON},
)
result = await hass.config_entries.flow.async_configure(
result["flow_id"], user_input={}
)
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "no_hardware_available"
async def test_ssdp_discovery_not_deconz_bridge(hass):
"""Test a non deconz bridge being discovered over ssdp."""
result = await hass.config_entries.flow.async_init(