diff --git a/homeassistant/config_entries.py b/homeassistant/config_entries.py index 0d4cc5fd102bd96dfc783fa373e262a60ace02d8..64eadeb0d7ebde77b6e515cda1fd78edf0d3f637 100644 --- a/homeassistant/config_entries.py +++ b/homeassistant/config_entries.py @@ -63,7 +63,7 @@ from .helpers.event import ( RANDOM_MICROSECOND_MIN, async_call_later, ) -from .helpers.frame import report +from .helpers.frame import ReportBehavior, report, report_usage from .helpers.json import json_bytes, json_bytes_sorted, json_fragment from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType from .loader import async_suggest_report_issue @@ -3168,17 +3168,21 @@ class OptionsFlow(ConfigEntryBaseFlow): class OptionsFlowWithConfigEntry(OptionsFlow): - """Base class for options flows with config entry and options.""" + """Base class for options flows with config entry and options. + + This class is being phased out, and should not be referenced in new code. + It is kept only for backward compatibility, and only for custom integrations. + """ def __init__(self, config_entry: ConfigEntry) -> None: """Initialize options flow.""" self._config_entry = config_entry self._options = deepcopy(dict(config_entry.options)) - report( - "inherits from OptionsFlowWithConfigEntry, which is deprecated " - "and will stop working in 2025.12", - error_if_integration=False, - error_if_core=True, + report_usage( + "inherits from OptionsFlowWithConfigEntry", + core_behavior=ReportBehavior.ERROR, + core_integration_behavior=ReportBehavior.ERROR, + custom_integration_behavior=ReportBehavior.IGNORE, ) @property diff --git a/tests/test_config_entries.py b/tests/test_config_entries.py index df464f6af1b3e3d7b0a1425bb635d77d63e268f1..eb2a719eab89824f06e6428d49a9d4842d0e1f05 100644 --- a/tests/test_config_entries.py +++ b/tests/test_config_entries.py @@ -5040,6 +5040,24 @@ async def test_async_wait_component_startup(hass: HomeAssistant) -> None: assert "test" in hass.config.components +@pytest.mark.parametrize( + "integration_frame_path", + ["homeassistant/components/my_integration", "homeassistant.core"], +) +@pytest.mark.usefixtures("mock_integration_frame") +async def test_options_flow_with_config_entry_core() -> None: + """Test that OptionsFlowWithConfigEntry cannot be used in core.""" + entry = MockConfigEntry( + domain="hue", + data={"first": True}, + options={"sub_dict": {"1": "one"}, "sub_list": ["one"]}, + ) + + with pytest.raises(RuntimeError, match="inherits from OptionsFlowWithConfigEntry"): + _ = config_entries.OptionsFlowWithConfigEntry(entry) + + +@pytest.mark.parametrize("integration_frame_path", ["custom_components/my_integration"]) @pytest.mark.usefixtures("mock_integration_frame") @patch.object(frame, "_REPORTED_INTEGRATIONS", set()) async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) -> None: @@ -5051,15 +5069,17 @@ async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) ) options_flow = config_entries.OptionsFlowWithConfigEntry(entry) - assert ( - "Detected that integration 'hue' inherits from OptionsFlowWithConfigEntry," - " which is deprecated and will stop working in 2025.12" in caplog.text - ) + assert caplog.text == "" # No deprecation warning for custom components + + # Ensure available at startup + assert options_flow.config_entry is entry + assert options_flow.options == entry.options - options_flow._options["sub_dict"]["2"] = "two" - options_flow._options["sub_list"].append("two") + options_flow.options["sub_dict"]["2"] = "two" + options_flow.options["sub_list"].append("two") - assert options_flow._options == { + # Ensure it does not mutate the entry options + assert options_flow.options == { "sub_dict": {"1": "one", "2": "two"}, "sub_list": ["one", "two"], }