Cleanup deprecated OptionsFlowWithConfigEntry (part 3) (#129756)

This commit is contained in:
epenet 2024-11-04 18:55:01 +01:00 committed by GitHub
parent 8870b657d1
commit d180ff417d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -3127,6 +3127,10 @@ class OptionsFlow(ConfigEntryBaseFlow):
) )
self._config_entry = value 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 @property
def options(self) -> dict[str, Any]: def options(self) -> dict[str, Any]:
"""Return a mutable copy of the config entry options. """Return a mutable copy of the config entry options.
@ -3135,7 +3139,7 @@ class OptionsFlow(ConfigEntryBaseFlow):
can only be referenced after initialisation. can only be referenced after initialisation.
""" """
if not hasattr(self, "_options"): if not hasattr(self, "_options"):
self._options = deepcopy(dict(self.config_entry.options)) self.initialize_options(self.config_entry)
return self._options return self._options
@options.setter @options.setter
@ -3161,7 +3165,7 @@ class OptionsFlowWithConfigEntry(OptionsFlow):
"inherits from OptionsFlowWithConfigEntry, which is deprecated " "inherits from OptionsFlowWithConfigEntry, which is deprecated "
"and will stop working in 2025.12", "and will stop working in 2025.12",
error_if_integration=False, error_if_integration=False,
error_if_core=False, error_if_core=True,
) )

View File

@ -16,7 +16,6 @@ from homeassistant.config_entries import (
ConfigFlow, ConfigFlow,
ConfigFlowResult, ConfigFlowResult,
OptionsFlow, OptionsFlow,
OptionsFlowWithConfigEntry,
) )
from homeassistant.core import HomeAssistant, callback, split_entity_id from homeassistant.core import HomeAssistant, callback, split_entity_id
from homeassistant.data_entry_flow import UnknownHandler from homeassistant.data_entry_flow import UnknownHandler
@ -403,7 +402,7 @@ class SchemaConfigFlowHandler(ConfigFlow, ABC):
) )
class SchemaOptionsFlowHandler(OptionsFlowWithConfigEntry): class SchemaOptionsFlowHandler(OptionsFlow):
"""Handle a schema based options flow.""" """Handle a schema based options flow."""
def __init__( def __init__(
@ -422,10 +421,8 @@ class SchemaOptionsFlowHandler(OptionsFlowWithConfigEntry):
options, which is the union of stored options and user input from the options options, which is the union of stored options and user input from the options
flow steps. flow steps.
""" """
super().__init__(config_entry) self.initialize_options(config_entry)
self._common_handler = SchemaCommonFlowHandler( self._common_handler = SchemaCommonFlowHandler(self, options_flow, self.options)
self, options_flow, self._options
)
self._async_options_flow_finished = async_options_flow_finished self._async_options_flow_finished = async_options_flow_finished
for step in options_flow: for step in options_flow: