diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 4f07c9cf574..c2481ae3fa3 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -2839,10 +2839,16 @@ class ConfigFlow(ConfigEntryBaseFlow): ) -> None: """Abort if current entries match all data. + Do not abort for the entry that is being updated by the current flow. Requires `already_configured` in strings.json in user visible flows. """ _async_abort_entries_match( - self._async_current_entries(include_ignore=False), match_dict + [ + entry + for entry in self._async_current_entries(include_ignore=False) + if entry.entry_id != self.context.get("entry_id") + ], + match_dict, ) @callback diff --git a/tests/components/pushover/test_config_flow.py b/tests/components/pushover/test_config_flow.py index 58485bfb427..a3c9ac3ccbb 100644 --- a/tests/components/pushover/test_config_flow.py +++ b/tests/components/pushover/test_config_flow.py @@ -217,7 +217,7 @@ async def test_reauth_with_existing_config(hass: HomeAssistant) -> None: result2 = await hass.config_entries.flow.async_configure( result["flow_id"], { - CONF_API_KEY: "MYAPIKEY2", + CONF_API_KEY: MOCK_CONFIG[CONF_API_KEY], }, ) diff --git a/tests/components/sabnzbd/test_config_flow.py b/tests/components/sabnzbd/test_config_flow.py index 98422e931ec..ec9044f4223 100644 --- a/tests/components/sabnzbd/test_config_flow.py +++ b/tests/components/sabnzbd/test_config_flow.py @@ -153,10 +153,10 @@ async def test_abort_already_configured( assert result["reason"] == "already_configured" -async def test_abort_reconfigure_already_configured( +async def test_abort_reconfigure_successful( hass: HomeAssistant, config_entry: MockConfigEntry ) -> None: - """Test that the reconfigure flow aborts if SABnzbd instance is already configured.""" + """Test that the reconfigure flow aborts successfully if SABnzbd instance is already configured.""" result = await config_entry.start_reconfigure_flow(hass) assert result["type"] is FlowResultType.FORM assert result["errors"] == {} @@ -166,4 +166,4 @@ async def test_abort_reconfigure_already_configured( VALID_CONFIG, ) assert result["type"] is FlowResultType.ABORT - assert result["reason"] == "already_configured" + assert result["reason"] == "reconfigure_successful" diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 75610c7d076..ffff19f2c46 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -5268,6 +5268,52 @@ async def test_async_abort_entries_match( assert result["reason"] == reason +@pytest.mark.parametrize( + ("matchers", "reason"), + [ + ({"host": "3.4.5.6", "ip": "1.2.3.4", "port": 23}, "no_match"), + ], +) +async def test_async_abort_entries_match_context( + hass: HomeAssistant, + manager: config_entries.ConfigEntries, + matchers: dict[str, str], + reason: str, +) -> None: + """Test aborting if matching config entries exist.""" + entry = MockConfigEntry( + domain="comp", data={"ip": "1.2.3.4", "host": "3.4.5.6", "port": 23} + ) + entry.add_to_hass(hass) + + mock_setup_entry = AsyncMock(return_value=True) + mock_integration(hass, MockModule("comp", async_setup_entry=mock_setup_entry)) + mock_platform(hass, "comp.config_flow", None) + + class TestFlow(config_entries.ConfigFlow): + """Test flow.""" + + VERSION = 1 + + async def async_step_reconfigure(self, user_input=None): + """Test user step.""" + self._async_abort_entries_match(matchers) + return self.async_abort(reason="no_match") + + with mock_config_flow("comp", TestFlow), mock_config_flow("invalid_flow", 5): + result = await manager.flow.async_init( + "comp", + context={ + "source": config_entries.SOURCE_RECONFIGURE, + "entry_id": entry.entry_id, + }, + ) + await hass.async_block_till_done() + + assert result["type"] == FlowResultType.ABORT + assert result["reason"] == reason + + @pytest.mark.parametrize( ("matchers", "reason"), [