diff --git a/homeassistant/components/unifiprotect/config_flow.py b/homeassistant/components/unifiprotect/config_flow.py index 720a46b4659..0890a962e5b 100644 --- a/homeassistant/components/unifiprotect/config_flow.py +++ b/homeassistant/components/unifiprotect/config_flow.py @@ -90,7 +90,11 @@ class ProtectFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): await self.async_set_unique_id(mac) source_ip = discovery_info["source_ip"] direct_connect_domain = discovery_info["direct_connect_domain"] - for entry in self._async_current_entries(include_ignore=False): + for entry in self._async_current_entries(): + if entry.source == config_entries.SOURCE_IGNORE: + if entry.unique_id == mac: + return self.async_abort(reason="already_configured") + continue entry_host = entry.data[CONF_HOST] entry_has_direct_connect = _host_is_direct_connect(entry_host) if entry.unique_id == mac: diff --git a/tests/components/unifiprotect/test_config_flow.py b/tests/components/unifiprotect/test_config_flow.py index fc5b2b32873..a1609984be3 100644 --- a/tests/components/unifiprotect/test_config_flow.py +++ b/tests/components/unifiprotect/test_config_flow.py @@ -723,3 +723,24 @@ async def test_discovered_by_unifi_discovery_direct_connect_on_different_interfa assert result["type"] == RESULT_TYPE_ABORT assert result["reason"] == "already_configured" + + +async def test_discovery_can_be_ignored(hass: HomeAssistant, mock_nvr: NVR) -> None: + """Test a discovery can be ignored.""" + mock_config = MockConfigEntry( + domain=DOMAIN, + data={}, + unique_id=DEVICE_MAC_ADDRESS.upper().replace(":", ""), + source=config_entries.SOURCE_IGNORE, + ) + mock_config.add_to_hass(hass) + with _patch_discovery(): + result = await hass.config_entries.flow.async_init( + DOMAIN, + context={"source": config_entries.SOURCE_DISCOVERY}, + data=UNIFI_DISCOVERY_DICT, + ) + await hass.async_block_till_done() + + assert result["type"] == RESULT_TYPE_ABORT + assert result["reason"] == "already_configured"