diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 0682d46924d..6a95707dcda 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -3127,10 +3127,6 @@ class OptionsFlow(ConfigEntryBaseFlow): ) self._config_entry = value - def initialize_options(self, config_entry: ConfigEntry) -> None: - """Initialize the options to a mutable copy of the config entry options.""" - self._options = deepcopy(dict(config_entry.options)) - @property def options(self) -> dict[str, Any]: """Return a mutable copy of the config entry options. @@ -3139,7 +3135,7 @@ class OptionsFlow(ConfigEntryBaseFlow): can only be referenced after initialisation. """ if not hasattr(self, "_options"): - self.initialize_options(self.config_entry) + self._options = deepcopy(dict(self.config_entry.options)) return self._options @options.setter diff --git a/homeassistant/helpers/schema_config_entry_flow.py b/homeassistant/helpers/schema_config_entry_flow.py index 58a44f9682d..b956a58398a 100644 --- a/homeassistant/helpers/schema_config_entry_flow.py +++ b/homeassistant/helpers/schema_config_entry_flow.py @@ -421,7 +421,9 @@ class SchemaOptionsFlowHandler(OptionsFlow): options, which is the union of stored options and user input from the options flow steps. """ - self.initialize_options(config_entry) + # Although `self.options` is most likely unused, it is safer to keep both + # `self.options` and `self._common_handler.options` referring to the same object + self._options = copy.deepcopy(dict(config_entry.options)) self._common_handler = SchemaCommonFlowHandler(self, options_flow, self.options) self._async_options_flow_finished = async_options_flow_finished diff --git a/tests/helpers/test_schema_config_entry_flow.py b/tests/helpers/test_schema_config_entry_flow.py index 877e3762d3b..e67525253bc 100644 --- a/tests/helpers/test_schema_config_entry_flow.py +++ b/tests/helpers/test_schema_config_entry_flow.py @@ -648,6 +648,10 @@ async def test_options_flow_state(hass: HomeAssistant) -> None: options_handler = hass.config_entries.options._progress[result["flow_id"]] assert options_handler._common_handler.flow_state == {"idx": None} + # Ensure that self.options and self._common_handler.options refer to the + # same mutable copy of the options + assert options_handler.options is options_handler._common_handler.options + # In step 1, flow state is updated with user input result = await hass.config_entries.options.async_configure( result["flow_id"], {"option1": "blublu"}