From 4784199038e1b8b090770fcaec2d3cb8815b1a88 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 4 Nov 2024 13:59:10 +0100 Subject: [PATCH] Fix aborting flows for single config entry integrations (#129805) --- homeassistant/config_entries.py | 1 + tests/test_config_entries.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index f533a62e753..ec0a559c76f 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -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 diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index e3f1d110ac0..822dca559a8 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -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 (