diff --git a/homeassistant/components/nut/config_flow.py b/homeassistant/components/nut/config_flow.py index 5d90d16f157..7cebf0c6759 100644 --- a/homeassistant/components/nut/config_flow.py +++ b/homeassistant/components/nut/config_flow.py @@ -216,6 +216,7 @@ class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN): existing_host_port_aliases = { _format_host_port_alias(entry.data) for entry in self._async_current_entries() + if CONF_HOST in entry.data } return _format_host_port_alias(user_input) in existing_host_port_aliases diff --git a/tests/components/nut/test_config_flow.py b/tests/components/nut/test_config_flow.py index 5a2155441b5..d86c0d8eb88 100644 --- a/tests/components/nut/test_config_flow.py +++ b/tests/components/nut/test_config_flow.py @@ -247,7 +247,25 @@ async def test_form_import_dupe(hass): entry.add_to_hass(hass) result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": "import"}, data=VALID_CONFIG + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=VALID_CONFIG + ) + assert result["type"] == "abort" + assert result["reason"] == "already_configured" + + +async def test_form_import_with_ignored_entry(hass): + """Test we get abort on duplicate import when there is an ignored one.""" + await setup.async_setup_component(hass, "persistent_notification", {}) + + entry = MockConfigEntry(domain=DOMAIN, data=VALID_CONFIG) + entry.add_to_hass(hass) + ignored_entry = MockConfigEntry( + domain=DOMAIN, data={}, source=config_entries.SOURCE_IGNORE + ) + ignored_entry.add_to_hass(hass) + + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=VALID_CONFIG ) assert result["type"] == "abort" assert result["reason"] == "already_configured"