From f13bdd0da43be09ebfec90304c019440254d268e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 12 Apr 2025 07:47:02 -1000 Subject: [PATCH] Add support for passing though `description_placeholders` to `_abort_if_unique_id_configured` (#142779) --- homeassistant/config_entries.py | 3 ++- tests/test_config_entries.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 3064fdd54bb..c58a33ad68d 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -2913,6 +2913,7 @@ class ConfigFlow(ConfigEntryBaseFlow): reload_on_update: bool = True, *, error: str = "already_configured", + description_placeholders: Mapping[str, str] | None = None, ) -> None: """Abort if the unique ID is already configured. @@ -2953,7 +2954,7 @@ class ConfigFlow(ConfigEntryBaseFlow): return if should_reload: self.hass.config_entries.async_schedule_reload(entry.entry_id) - raise data_entry_flow.AbortFlow(error) + raise data_entry_flow.AbortFlow(error, description_placeholders) async def async_set_unique_id( self, unique_id: str | None = None, *, raise_on_progress: bool = True diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index 13ecd855624..ba599c88518 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -3259,7 +3259,9 @@ async def test_unique_id_update_existing_entry_without_reload( """Test user step.""" await self.async_set_unique_id("mock-unique-id") self._abort_if_unique_id_configured( - updates={"host": "1.1.1.1"}, reload_on_update=False + updates={"host": "1.1.1.1"}, + reload_on_update=False, + description_placeholders={"title": "Other device"}, ) with ( @@ -3275,6 +3277,7 @@ async def test_unique_id_update_existing_entry_without_reload( assert result["type"] == FlowResultType.ABORT assert result["reason"] == "already_configured" + assert result["description_placeholders"]["title"] == "Other device" assert entry.data["host"] == "1.1.1.1" assert entry.data["additional"] == "data" assert len(async_reload.mock_calls) == 0 @@ -3309,7 +3312,9 @@ async def test_unique_id_update_existing_entry_with_reload( """Test user step.""" await self.async_set_unique_id("mock-unique-id") await self._abort_if_unique_id_configured( - updates=updates, reload_on_update=True + updates=updates, + reload_on_update=True, + description_placeholders={"title": "Other device"}, ) with ( @@ -3325,6 +3330,7 @@ async def test_unique_id_update_existing_entry_with_reload( assert result["type"] == FlowResultType.ABORT assert result["reason"] == "already_configured" + assert result["description_placeholders"]["title"] == "Other device" assert entry.data["host"] == "1.1.1.1" assert entry.data["additional"] == "data" assert len(async_reload.mock_calls) == 1 @@ -3345,6 +3351,7 @@ async def test_unique_id_update_existing_entry_with_reload( assert result["type"] == FlowResultType.ABORT assert result["reason"] == "already_configured" + assert result["description_placeholders"]["title"] == "Other device" assert entry.data["host"] == "2.2.2.2" assert entry.data["additional"] == "data" assert len(async_reload.mock_calls) == 0