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: ) -> ConfigFlowResult:
"""Update config entry, reload config entry and finish config flow. """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, Any update listener will be removed before updating the entry as the config entry
unless `reload_even_if_entry_is_unchanged` is set to `True`. will be reloaded in the case the entry has been updated.
:param data: replace the entry data with new data :param data: replace the entry data with new data
:param data_updates: add items from data_updates to entry data - existing keys :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: if data is not UNDEFINED:
raise ValueError("Cannot set both data and data_updates") raise ValueError("Cannot set both data and data_updates")
data = entry.data | 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 = [] entry.update_listeners = []
result = self.hass.config_entries.async_update_entry( result = self.hass.config_entries.async_update_entry(
entry=entry, entry=entry,
unique_id=unique_id, unique_id=unique_id,
@ -3257,8 +3263,13 @@ class ConfigFlow(ConfigEntryBaseFlow):
data=data, data=data,
options=options, options=options,
) )
if reload_even_if_entry_is_unchanged or result: if reload_even_if_entry_is_unchanged or result:
self.hass.config_entries.async_schedule_reload(entry.entry_id) 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: if reason is UNDEFINED:
reason = "reauth_successful" reason = "reauth_successful"
if self.source == SOURCE_RECONFIGURE: if self.source == SOURCE_RECONFIGURE: