Log a warning when replacing existing config entry with same unique id (#130567)

* Log a warning when replacing existing config entry with same unique id

* Exclude mobile_app

* Ignore custom integrations

* Apply suggestions from code review

* Apply suggestions from code review

* Update config_entries.py

* Fix handler

* Adjust and add tests

* Apply suggestions from code review

* Apply suggestions from code review

* Update comment

* Update config_entries.py

* Apply suggestions from code review
This commit is contained in:
epenet
2025-02-28 14:20:39 +01:00
committed by GitHub
parent d157919da2
commit 030a1460de
2 changed files with 77 additions and 0 deletions

View File

@@ -1628,6 +1628,23 @@ class ConfigEntriesFlowManager(
result["handler"], flow.unique_id
)
if existing_entry is not None and flow.handler != "mobile_app":
# This causes the old entry to be removed and replaced, when the flow
# should instead be aborted.
# In case of manual flows, integrations should implement options, reauth,
# reconfigure to allow the user to change settings.
# In case of non user visible flows, the integration should optionally
# update the existing entry before aborting.
# see https://developers.home-assistant.io/blog/2025/01/16/config-flow-unique-id/
report_usage(
"creates a config entry when another entry with the same unique ID "
"exists",
core_behavior=ReportBehavior.LOG,
core_integration_behavior=ReportBehavior.LOG,
custom_integration_behavior=ReportBehavior.LOG,
integration_domain=flow.handler,
)
# Unload the entry before setting up the new one.
if existing_entry is not None and existing_entry.state.recoverable:
await self.config_entries.async_unload(existing_entry.entry_id)