mirror of
https://github.com/home-assistant/core.git
synced 2026-05-05 04:14:32 +02:00
Remove deprecated config entry handling in OptionsFlow (#155958)
This commit is contained in:
@@ -213,14 +213,14 @@ class HomeAssistantConnectZBT2OptionsFlowHandler(
|
||||
"""Instantiate options flow."""
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._usb_info = get_usb_service_info(self.config_entry)
|
||||
self._usb_info = get_usb_service_info(self._config_entry)
|
||||
self._hardware_name = HARDWARE_NAME
|
||||
self._device = self._usb_info.device
|
||||
|
||||
self._probed_firmware_info = FirmwareInfo(
|
||||
device=self._device,
|
||||
firmware_type=ApplicationType(self.config_entry.data[FIRMWARE]),
|
||||
firmware_version=self.config_entry.data[FIRMWARE_VERSION],
|
||||
firmware_type=ApplicationType(self._config_entry.data[FIRMWARE]),
|
||||
firmware_version=self._config_entry.data[FIRMWARE_VERSION],
|
||||
source="guess",
|
||||
owners=[],
|
||||
)
|
||||
|
||||
@@ -275,17 +275,17 @@ class HomeAssistantSkyConnectOptionsFlowHandler(
|
||||
"""Instantiate options flow."""
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._usb_info = get_usb_service_info(self.config_entry)
|
||||
self._usb_info = get_usb_service_info(self._config_entry)
|
||||
self._hw_variant = HardwareVariant.from_usb_product_name(
|
||||
self.config_entry.data[PRODUCT]
|
||||
self._config_entry.data[PRODUCT]
|
||||
)
|
||||
self._hardware_name = self._hw_variant.full_name
|
||||
self._device = self._usb_info.device
|
||||
|
||||
self._probed_firmware_info = FirmwareInfo(
|
||||
device=self._device,
|
||||
firmware_type=ApplicationType(self.config_entry.data[FIRMWARE]),
|
||||
firmware_version=self.config_entry.data[FIRMWARE_VERSION],
|
||||
firmware_type=ApplicationType(self._config_entry.data[FIRMWARE]),
|
||||
firmware_version=self._config_entry.data[FIRMWARE_VERSION],
|
||||
source="guess",
|
||||
owners=[],
|
||||
)
|
||||
|
||||
@@ -348,7 +348,7 @@ class HomeAssistantYellowOptionsFlowHandler(
|
||||
|
||||
self._probed_firmware_info = FirmwareInfo(
|
||||
device=self._device,
|
||||
firmware_type=ApplicationType(self.config_entry.data["firmware"]),
|
||||
firmware_type=ApplicationType(self._config_entry.data["firmware"]),
|
||||
firmware_version=None,
|
||||
source="guess",
|
||||
owners=[],
|
||||
|
||||
@@ -3736,9 +3736,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
|
||||
@@ -3779,26 +3776,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.
|
||||
|
||||
@@ -130,12 +130,12 @@ class FakeFirmwareOptionsFlowHandler(BaseFirmwareOptionsFlow):
|
||||
"""Instantiate options flow."""
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._device = self.config_entry.data["device"]
|
||||
self._hardware_name = self.config_entry.data["hardware"]
|
||||
self._device = self._config_entry.data["device"]
|
||||
self._hardware_name = self._config_entry.data["hardware"]
|
||||
|
||||
self._probed_firmware_info = FirmwareInfo(
|
||||
device=self._device,
|
||||
firmware_type=ApplicationType(self.config_entry.data["firmware"]),
|
||||
firmware_type=ApplicationType(self._config_entry.data["firmware"]),
|
||||
firmware_version=None,
|
||||
source="guess",
|
||||
owners=[],
|
||||
|
||||
@@ -6240,16 +6240,21 @@ async def test_options_flow_with_config_entry_core() -> None:
|
||||
|
||||
|
||||
@pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"])
|
||||
@pytest.mark.usefixtures("hass", "mock_integration_frame")
|
||||
async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) -> None:
|
||||
@pytest.mark.usefixtures("mock_integration_frame")
|
||||
async def test_options_flow_with_config_entry(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test that OptionsFlowWithConfigEntry doesn't mutate entry options."""
|
||||
entry = MockConfigEntry(
|
||||
domain="hue",
|
||||
data={"first": True},
|
||||
options={"sub_dict": {"1": "one"}, "sub_list": ["one"]},
|
||||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
options_flow = config_entries.OptionsFlowWithConfigEntry(entry)
|
||||
options_flow.hass = hass
|
||||
options_flow.handler = entry.entry_id
|
||||
assert caplog.text == "" # No deprecation warning for custom components
|
||||
|
||||
# Ensure available at startup
|
||||
@@ -9322,12 +9327,12 @@ async def test_options_flow_automatic_reload(
|
||||
|
||||
@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(
|
||||
async def test_options_flow_set_config_entry_fails(
|
||||
hass: HomeAssistant,
|
||||
manager: config_entries.ConfigEntries,
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test that setting config_entry explicitly still works."""
|
||||
"""Test that setting config_entry explicitly fails."""
|
||||
original_entry = MockConfigEntry(domain="my_integration", data={})
|
||||
original_entry.add_to_hass(hass)
|
||||
|
||||
@@ -9370,20 +9375,17 @@ async def test_options_flow_deprecated_config_entry_setter(
|
||||
|
||||
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
|
||||
)
|
||||
with (
|
||||
mock_config_flow("my_integration", TestFlow),
|
||||
pytest.raises(
|
||||
AttributeError,
|
||||
match="property 'config_entry' of "
|
||||
"'test_options_flow_set_config_entry_fails.<locals>."
|
||||
"TestFlow.async_get_options_flow.<locals>._OptionsFlow'"
|
||||
" object has no setter",
|
||||
),
|
||||
):
|
||||
await hass.config_entries.options.async_init(original_entry.entry_id)
|
||||
|
||||
|
||||
async def test_add_description_placeholder_automatically(
|
||||
|
||||
Reference in New Issue
Block a user