From 3a693ce12a8d9e9fab823061f883281c6db70c32 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Wed, 18 Dec 2024 18:05:16 +0000 Subject: [PATCH] Mods --- homeassistant/config_entries.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index b9222052a02..65806cbcb48 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -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: