This commit is contained in:
G Johansson 2024-12-18 18:05:16 +00:00
parent 6d83b48448
commit 3a693ce12a

View File

@ -3229,8 +3229,8 @@ class ConfigFlow(ConfigEntryBaseFlow):
) -> ConfigFlowResult:
"""Update config entry, reload config entry and finish config flow.
Reloading is only done if the entry was changed and there is no update listener,
unless `reload_even_if_entry_is_unchanged` is set to `True`.
Any update listener will be removed before updating the entry as the config entry
will be reloaded in the case the entry has been updated.
:param data: replace the entry data with new data
:param data_updates: add items from data_updates to entry data - existing keys
@ -3249,7 +3249,13 @@ class ConfigFlow(ConfigEntryBaseFlow):
if data is not UNDEFINED:
raise ValueError("Cannot set both data and data_updates")
data = entry.data | data_updates
restore_update_listeners = []
if entry.update_listeners:
# Save a copy of the update listeners to be restored in case no reload.
restore_update_listeners = list(entry.update_listeners)
entry.update_listeners = []
result = self.hass.config_entries.async_update_entry(
entry=entry,
unique_id=unique_id,
@ -3257,8 +3263,13 @@ class ConfigFlow(ConfigEntryBaseFlow):
data=data,
options=options,
)
if reload_even_if_entry_is_unchanged or result:
self.hass.config_entries.async_schedule_reload(entry.entry_id)
else:
# Restore the update listeners in the case an update did not occur.
entry.update_listeners = restore_update_listeners
if reason is UNDEFINED:
reason = "reauth_successful"
if self.source == SOURCE_RECONFIGURE: