Prevent nut config flow error when checking ignored entries (#38372)

This commit is contained in:
J. Nick Koston 2020-07-29 11:20:19 -10:00 committed by Paulus Schoutsen
parent 0ecaab1a7d
commit 293655f988
2 changed files with 20 additions and 1 deletions

View file

@ -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

View file

@ -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"