mirror of
https://github.com/home-assistant/core.git
synced 2025-07-30 08:47:09 +00:00
Remove deprecated setting of _config_entry in OptionsFlow
This commit is contained in:
parent
26fe23eb5c
commit
23dee4400a
@ -3506,9 +3506,6 @@ class OptionsFlow(ConfigEntryBaseFlow):
|
||||
|
||||
handler: str
|
||||
|
||||
_config_entry: ConfigEntry
|
||||
"""For compatibility only - to be removed in 2025.12"""
|
||||
|
||||
@callback
|
||||
def _async_abort_entries_match(
|
||||
self, match_dict: dict[str, Any] | None = None
|
||||
@ -3549,26 +3546,10 @@ class OptionsFlow(ConfigEntryBaseFlow):
|
||||
Please note that this is not available inside `__init__` method, and
|
||||
can only be referenced after initialisation.
|
||||
"""
|
||||
# For compatibility only - to be removed in 2025.12
|
||||
if hasattr(self, "_config_entry"):
|
||||
return self._config_entry
|
||||
|
||||
if self.hass is None:
|
||||
raise ValueError("The config entry is not available during initialisation")
|
||||
return self.hass.config_entries.async_get_known_entry(self._config_entry_id)
|
||||
|
||||
@config_entry.setter
|
||||
def config_entry(self, value: ConfigEntry) -> None:
|
||||
"""Set the config entry value."""
|
||||
report_usage(
|
||||
"sets option flow config_entry explicitly, which is deprecated",
|
||||
core_behavior=ReportBehavior.ERROR,
|
||||
core_integration_behavior=ReportBehavior.ERROR,
|
||||
custom_integration_behavior=ReportBehavior.LOG,
|
||||
breaks_in_ha_version="2025.12",
|
||||
)
|
||||
self._config_entry = value
|
||||
|
||||
|
||||
class OptionsFlowWithConfigEntry(OptionsFlow):
|
||||
"""Base class for options flows with config entry and options.
|
||||
@ -3588,6 +3569,15 @@ class OptionsFlowWithConfigEntry(OptionsFlow):
|
||||
custom_integration_behavior=ReportBehavior.IGNORE,
|
||||
)
|
||||
|
||||
@property
|
||||
def config_entry(self) -> ConfigEntry:
|
||||
"""Return the config entry linked to the current options flow.
|
||||
|
||||
Please note that this is not available inside `__init__` method, and
|
||||
can only be referenced after initialisation.
|
||||
"""
|
||||
return self._config_entry
|
||||
|
||||
@property
|
||||
def options(self) -> dict[str, Any]:
|
||||
"""Return a mutable copy of the config entry options."""
|
||||
|
@ -8654,72 +8654,6 @@ async def test_options_flow_config_entry(
|
||||
assert result["reason"] == "abort"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"])
|
||||
@pytest.mark.usefixtures("mock_integration_frame")
|
||||
async def test_options_flow_deprecated_config_entry_setter(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that setting config_entry explicitly still works."""
|
||||
original_entry = MockConfigEntry(domain="my_integration", data={})
|
||||
original_entry.add_to_hass(hass)
|
||||
|
||||
mock_setup_entry = AsyncMock(return_value=True)
|
||||
|
||||
mock_integration(
|
||||
hass, MockModule("my_integration", async_setup_entry=mock_setup_entry)
|
||||
)
|
||||
mock_platform(hass, "my_integration.config_flow", None)
|
||||
|
||||
class TestFlow(config_entries.ConfigFlow):
|
||||
"""Test flow."""
|
||||
|
||||
@staticmethod
|
||||
@callback
|
||||
def async_get_options_flow(config_entry):
|
||||
"""Test options flow."""
|
||||
|
||||
class _OptionsFlow(config_entries.OptionsFlow):
|
||||
"""Test flow."""
|
||||
|
||||
def __init__(self, entry) -> None:
|
||||
"""Test initialisation."""
|
||||
self.config_entry = entry
|
||||
|
||||
async def async_step_init(self, user_input=None):
|
||||
"""Test user step."""
|
||||
errors = {}
|
||||
if user_input is not None:
|
||||
if user_input.get("abort"):
|
||||
return self.async_abort(reason="abort")
|
||||
|
||||
errors["entry_id"] = self._config_entry_id
|
||||
try:
|
||||
errors["entry"] = self.config_entry
|
||||
except config_entries.UnknownEntry as err:
|
||||
errors["entry"] = err
|
||||
|
||||
return self.async_show_form(step_id="init", errors=errors)
|
||||
|
||||
return _OptionsFlow(config_entry)
|
||||
|
||||
with mock_config_flow("my_integration", TestFlow):
|
||||
result = await hass.config_entries.options.async_init(original_entry.entry_id)
|
||||
|
||||
options_flow = hass.config_entries.options._progress.get(result["flow_id"])
|
||||
assert options_flow.config_entry is original_entry
|
||||
|
||||
assert (
|
||||
"Detected that custom integration 'my_integration' sets option flow "
|
||||
"config_entry explicitly, which is deprecated at "
|
||||
"custom_components/my_integration/light.py, line 23: "
|
||||
"self.light.is_on. This will stop working in Home Assistant 2025.12, please "
|
||||
"report it to the author of the 'my_integration' custom integration"
|
||||
in caplog.text
|
||||
)
|
||||
|
||||
|
||||
async def test_add_description_placeholder_automatically(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
|
Loading…
x
Reference in New Issue
Block a user