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

pull/129810/head
Erik Montnemery 2024-11-04 13:59:10 +01:00 committed by GitHub
parent df35c8e707
commit 4784199038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -1457,6 +1457,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

@ -5843,8 +5843,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(
@ -5872,6 +5884,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 (