Handle an unsupported device in the Broadlink config flow (#40242)

This commit is contained in:
Felipe Martins Diel authored and GitHub committed 2020-09-18 15:29:26 +02:00
1 parent ff3fd63eea
commit 976d8f7abe
5 files changed
+62 -1

No files matched your search

+10
View File
@@ -56,6 +56,16 @@ BROADLINK_DEVICES = {
20025,
5,
),
"Kitchen": ( # Not supported.
"192.168.0.64",
"34ea34b61d2c",
"LB1",
"Broadlink",
"SmartBulb",
0x504E,
57,
5,
),
}
@@ -175,6 +175,25 @@ async def test_flow_user_device_not_found(hass):
assert result["errors"] == {"base": "cannot_connect"}
async def test_flow_user_device_not_supported(hass):
"""Test we handle a device not supported in the user step."""
device = get_device("Kitchen")
mock_api = device.get_mock_api()
result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": config_entries.SOURCE_USER}
)
with patch(DEVICE_DISCOVERY, return_value=[mock_api]):
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{"host": device.host},
)
assert result["type"] == "abort"
assert result["reason"] == "not_supported"
async def test_flow_user_network_unreachable(hass):
"""Test we handle a network unreachable in the user step."""
result = await hass.config_entries.flow.async_init(
@@ -634,6 +653,22 @@ async def test_flow_import_device_not_found(hass):
assert result["reason"] == "cannot_connect"
async def test_flow_import_device_not_supported(hass):
"""Test we handle a device not supported in the import step."""
device = get_device("Kitchen")
mock_api = device.get_mock_api()
with patch(DEVICE_DISCOVERY, return_value=[mock_api]):
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": config_entries.SOURCE_IMPORT},
data={"host": device.host},
)
assert result["type"] == "abort"
assert result["reason"] == "not_supported"
async def test_flow_import_invalid_ip_address(hass):
"""Test we handle an invalid IP address in the import step."""
with patch(DEVICE_DISCOVERY, side_effect=OSError(errno.EINVAL, None)):