Add support for passing though description_placeholders to _abort_if_unique_id_configured (#142779)

This commit is contained in:
J. Nick Koston 2025-04-12 07:47:02 -10:00 committed by GitHub
parent 3489ea30dd
commit f13bdd0da4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -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