mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Only apply OptionsFlowWithConfigEntry deprecation to core (#130054)
* Only apply OptionsFlowWithConfigEntry deprecation to core * Fix match string in pytest.raises * Improve coverage
This commit is contained in:
parent
6b90d8ff1a
commit
353ccf3ea7
@ -63,7 +63,7 @@ from .helpers.event import (
|
|||||||
RANDOM_MICROSECOND_MIN,
|
RANDOM_MICROSECOND_MIN,
|
||||||
async_call_later,
|
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.json import json_bytes, json_bytes_sorted, json_fragment
|
||||||
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
|
from .helpers.typing import UNDEFINED, ConfigType, DiscoveryInfoType, UndefinedType
|
||||||
from .loader import async_suggest_report_issue
|
from .loader import async_suggest_report_issue
|
||||||
@ -3168,17 +3168,21 @@ class OptionsFlow(ConfigEntryBaseFlow):
|
|||||||
|
|
||||||
|
|
||||||
class OptionsFlowWithConfigEntry(OptionsFlow):
|
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:
|
def __init__(self, config_entry: ConfigEntry) -> None:
|
||||||
"""Initialize options flow."""
|
"""Initialize options flow."""
|
||||||
self._config_entry = config_entry
|
self._config_entry = config_entry
|
||||||
self._options = deepcopy(dict(config_entry.options))
|
self._options = deepcopy(dict(config_entry.options))
|
||||||
report(
|
report_usage(
|
||||||
"inherits from OptionsFlowWithConfigEntry, which is deprecated "
|
"inherits from OptionsFlowWithConfigEntry",
|
||||||
"and will stop working in 2025.12",
|
core_behavior=ReportBehavior.ERROR,
|
||||||
error_if_integration=False,
|
core_integration_behavior=ReportBehavior.ERROR,
|
||||||
error_if_core=True,
|
custom_integration_behavior=ReportBehavior.IGNORE,
|
||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -5040,6 +5040,24 @@ async def test_async_wait_component_startup(hass: HomeAssistant) -> None:
|
|||||||
assert "test" in hass.config.components
|
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")
|
@pytest.mark.usefixtures("mock_integration_frame")
|
||||||
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
|
@patch.object(frame, "_REPORTED_INTEGRATIONS", set())
|
||||||
async def test_options_flow_with_config_entry(caplog: pytest.LogCaptureFixture) -> None:
|
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)
|
options_flow = config_entries.OptionsFlowWithConfigEntry(entry)
|
||||||
assert (
|
assert caplog.text == "" # No deprecation warning for custom components
|
||||||
"Detected that integration 'hue' inherits from OptionsFlowWithConfigEntry,"
|
|
||||||
" which is deprecated and will stop working in 2025.12" in caplog.text
|
|
||||||
)
|
|
||||||
|
|
||||||
options_flow._options["sub_dict"]["2"] = "two"
|
# Ensure available at startup
|
||||||
options_flow._options["sub_list"].append("two")
|
assert options_flow.config_entry is entry
|
||||||
|
assert options_flow.options == entry.options
|
||||||
|
|
||||||
assert options_flow._options == {
|
options_flow.options["sub_dict"]["2"] = "two"
|
||||||
|
options_flow.options["sub_list"].append("two")
|
||||||
|
|
||||||
|
# Ensure it does not mutate the entry options
|
||||||
|
assert options_flow.options == {
|
||||||
"sub_dict": {"1": "one", "2": "two"},
|
"sub_dict": {"1": "one", "2": "two"},
|
||||||
"sub_list": ["one", "two"],
|
"sub_list": ["one", "two"],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user