From e85e91bdb02d5c39070b716e241831e75f44f0f0 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 28 Jan 2022 23:14:30 -0600 Subject: [PATCH] Fix uncaught exception during isy994 dhcp discovery with ignored entry (#65165) --- .../components/isy994/config_flow.py | 2 ++ tests/components/isy994/test_config_flow.py | 31 ++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/isy994/config_flow.py b/homeassistant/components/isy994/config_flow.py index 7289f7d416e..4e700df24cb 100644 --- a/homeassistant/components/isy994/config_flow.py +++ b/homeassistant/components/isy994/config_flow.py @@ -158,6 +158,8 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): existing_entry = await self.async_set_unique_id(isy_mac) if not existing_entry: return + if existing_entry.source == config_entries.SOURCE_IGNORE: + raise data_entry_flow.AbortFlow("already_configured") parsed_url = urlparse(existing_entry.data[CONF_HOST]) if parsed_url.hostname != ip_address: new_netloc = ip_address diff --git a/tests/components/isy994/test_config_flow.py b/tests/components/isy994/test_config_flow.py index e9a4c5dc4fb..b16f5c0070d 100644 --- a/tests/components/isy994/test_config_flow.py +++ b/tests/components/isy994/test_config_flow.py @@ -16,7 +16,12 @@ from homeassistant.components.isy994.const import ( ISY_URL_POSTFIX, UDN_UUID_PREFIX, ) -from homeassistant.config_entries import SOURCE_DHCP, SOURCE_IMPORT, SOURCE_SSDP +from homeassistant.config_entries import ( + SOURCE_DHCP, + SOURCE_IGNORE, + SOURCE_IMPORT, + SOURCE_SSDP, +) from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME from homeassistant.core import HomeAssistant @@ -595,3 +600,27 @@ async def test_form_dhcp_existing_entry_preserves_port(hass: HomeAssistant): assert result["reason"] == "already_configured" assert entry.data[CONF_HOST] == f"http://1.2.3.4:1443{ISY_URL_POSTFIX}" assert entry.data[CONF_USERNAME] == "bob" + + +async def test_form_dhcp_existing_ignored_entry(hass: HomeAssistant): + """Test we handled an ignored entry from dhcp.""" + + entry = MockConfigEntry( + domain=DOMAIN, data={}, unique_id=MOCK_UUID, source=SOURCE_IGNORE + ) + entry.add_to_hass(hass) + + with patch(PATCH_CONNECTION, return_value=MOCK_CONFIG_RESPONSE): + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": SOURCE_DHCP}, + data=dhcp.DhcpServiceInfo( + ip="1.2.3.4", + hostname="isy994-ems", + macaddress=MOCK_MAC, + ), + ) + await hass.async_block_till_done() + + assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT + assert result["reason"] == "already_configured"