Fix aborting flows for single config entry integrations (#129805)

This commit is contained in:
Erik Montnemery 2024-11-04 13:59:10 +01:00 committed by Paulus Schoutsen
parent 7084b3b52c
commit 9349292464
2 changed files with 23 additions and 1 deletions

View File

@ -1446,6 +1446,7 @@ class ConfigEntriesFlowManager(
or progress_unique_id == DEFAULT_DISCOVERY_UNIQUE_ID
):
self.async_abort(progress_flow_id)
continue
# Abort any flows in progress for the same handler
# when integration allows only one config entry

View File

@ -5741,8 +5741,20 @@ async def test_avoid_adding_second_config_entry_on_single_config_entry(
assert result["translation_domain"] == HOMEASSISTANT_DOMAIN
@pytest.mark.parametrize(
("flow_1_unique_id", "flow_2_unique_id"),
[
(None, None),
("very_unique", "very_unique"),
(None, config_entries.DEFAULT_DISCOVERY_UNIQUE_ID),
("very_unique", config_entries.DEFAULT_DISCOVERY_UNIQUE_ID),
],
)
async def test_in_progress_get_canceled_when_entry_is_created(
hass: HomeAssistant, manager: config_entries.ConfigEntries
hass: HomeAssistant,
manager: config_entries.ConfigEntries,
flow_1_unique_id: str | None,
flow_2_unique_id: str | None,
) -> None:
"""Test that we abort all in progress flows when a new entry is created on a single instance only integration."""
integration = loader.Integration(
@ -5770,6 +5782,15 @@ async def test_in_progress_get_canceled_when_entry_is_created(
if user_input is not None:
return self.async_create_entry(title="Test Title", data=user_input)
await self.async_set_unique_id(flow_1_unique_id, raise_on_progress=False)
return self.async_show_form(step_id="user")
async def async_step_zeroconfg(self, user_input=None):
"""Test user step."""
if user_input is not None:
return self.async_create_entry(title="Test Title", data=user_input)
await self.async_set_unique_id(flow_2_unique_id, raise_on_progress=False)
return self.async_show_form(step_id="user")
with (