Skip to content

Commit

Permalink
Remove deprecated data entry flow constants (home-assistant#131800)
Browse files Browse the repository at this point in the history
* Remove deprecated data entry flow constants

* Fix

* Fix

* Fix

* Fix

---------

Co-authored-by: epenet <[email protected]>
  • Loading branch information
edenhaus and epenet authored Nov 28, 2024
1 parent d596b41 commit a68cf21
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 70 deletions.
15 changes: 5 additions & 10 deletions homeassistant/components/yamaha_musiccast/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
from aiomusiccast import MusicCastConnectionException, MusicCastDevice
import voluptuous as vol

from homeassistant import data_entry_flow
from homeassistant.components import ssdp
from homeassistant.config_entries import ConfigFlow
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.const import CONF_HOST
from homeassistant.helpers.aiohttp_client import async_get_clientsession

Expand All @@ -33,7 +32,7 @@ class MusicCastFlowHandler(ConfigFlow, domain=DOMAIN):

async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> data_entry_flow.ConfigFlowResult:
) -> ConfigFlowResult:
"""Handle a flow initiated by the user."""
# Request user input, unless we are preparing discovery flow
if user_input is None:
Expand Down Expand Up @@ -73,9 +72,7 @@ async def async_step_user(

return self._show_setup_form(errors)

def _show_setup_form(
self, errors: dict | None = None
) -> data_entry_flow.ConfigFlowResult:
def _show_setup_form(self, errors: dict | None = None) -> ConfigFlowResult:
"""Show the setup form to the user."""
return self.async_show_form(
step_id="user",
Expand All @@ -85,7 +82,7 @@ def _show_setup_form(

async def async_step_ssdp(
self, discovery_info: ssdp.SsdpServiceInfo
) -> data_entry_flow.ConfigFlowResult:
) -> ConfigFlowResult:
"""Handle ssdp discoveries."""
if not await MusicCastDevice.check_yamaha_ssdp(
discovery_info.ssdp_location, async_get_clientsession(self.hass)
Expand Down Expand Up @@ -117,9 +114,7 @@ async def async_step_ssdp(

return await self.async_step_confirm()

async def async_step_confirm(
self, user_input=None
) -> data_entry_flow.ConfigFlowResult:
async def async_step_confirm(self, user_input=None) -> ConfigFlowResult:
"""Allow the user to confirm adding the device."""
if user_input is not None:
return self.async_create_entry(
Expand Down
36 changes: 1 addition & 35 deletions homeassistant/data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import copy
from dataclasses import dataclass
from enum import StrEnum
from functools import partial
import logging
from types import MappingProxyType
from typing import Any, Generic, Required, TypedDict, cast
Expand All @@ -20,12 +19,6 @@

from .core import HomeAssistant, callback
from .exceptions import HomeAssistantError
from .helpers.deprecation import (
DeprecatedConstantEnum,
all_with_deprecated_constants,
check_if_deprecated_constant,
dir_with_deprecated_constants,
)
from .helpers.frame import ReportBehavior, report_usage
from .loader import async_suggest_report_issue
from .util import uuid as uuid_util
Expand All @@ -46,26 +39,6 @@ class FlowResultType(StrEnum):
MENU = "menu"


# RESULT_TYPE_* is deprecated, to be removed in 2025.1
_DEPRECATED_RESULT_TYPE_FORM = DeprecatedConstantEnum(FlowResultType.FORM, "2025.1")
_DEPRECATED_RESULT_TYPE_CREATE_ENTRY = DeprecatedConstantEnum(
FlowResultType.CREATE_ENTRY, "2025.1"
)
_DEPRECATED_RESULT_TYPE_ABORT = DeprecatedConstantEnum(FlowResultType.ABORT, "2025.1")
_DEPRECATED_RESULT_TYPE_EXTERNAL_STEP = DeprecatedConstantEnum(
FlowResultType.EXTERNAL_STEP, "2025.1"
)
_DEPRECATED_RESULT_TYPE_EXTERNAL_STEP_DONE = DeprecatedConstantEnum(
FlowResultType.EXTERNAL_STEP_DONE, "2025.1"
)
_DEPRECATED_RESULT_TYPE_SHOW_PROGRESS = DeprecatedConstantEnum(
FlowResultType.SHOW_PROGRESS, "2025.1"
)
_DEPRECATED_RESULT_TYPE_SHOW_PROGRESS_DONE = DeprecatedConstantEnum(
FlowResultType.SHOW_PROGRESS_DONE, "2025.1"
)
_DEPRECATED_RESULT_TYPE_MENU = DeprecatedConstantEnum(FlowResultType.MENU, "2025.1")

# Event that is fired when a flow is progressed via external or progress source.
EVENT_DATA_ENTRY_FLOW_PROGRESSED = "data_entry_flow_progressed"

Expand Down Expand Up @@ -126,6 +99,7 @@ def __init__(
schema_errors: dict[str, Any],
**kwargs: Any,
) -> None:
"""Initialize an invalid data exception."""
super().__init__(message, path, error_message, **kwargs)
self.schema_errors = schema_errors

Expand Down Expand Up @@ -929,11 +903,3 @@ def __init__(
def __call__(self, value: Any) -> Any:
"""Validate input."""
return self.schema(value)


# These can be removed if no deprecated constant are in this module anymore
__getattr__ = partial(check_if_deprecated_constant, module_globals=globals())
__dir__ = partial(
dir_with_deprecated_constants, module_globals_keys=[*globals().keys()]
)
__all__ = all_with_deprecated_constants(globals())
8 changes: 4 additions & 4 deletions tests/components/azure_data_explorer/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def test_config_flow(hass: HomeAssistant, mock_setup_entry: AsyncMock) ->
BASE_CONFIG.copy(),
)

assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result2["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
assert result2["title"] == "cluster.region.kusto.windows.net"
mock_setup_entry.assert_called_once()

Expand Down Expand Up @@ -59,12 +59,12 @@ async def test_config_flow_errors(
result["flow_id"],
BASE_CONFIG.copy(),
)
assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["type"] == data_entry_flow.FlowResultType.FORM
assert result2["errors"] == {"base": expected}

await hass.async_block_till_done()

assert result2["type"] == data_entry_flow.RESULT_TYPE_FORM
assert result2["type"] == data_entry_flow.FlowResultType.FORM

# Retest error handling if error is corrected and connection is successful

Expand All @@ -77,4 +77,4 @@ async def test_config_flow_errors(

await hass.async_block_till_done()

assert result3["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
assert result3["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
22 changes: 1 addition & 21 deletions tests/test_data_entry_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,7 @@
from homeassistant.helpers import config_validation as cv
from homeassistant.util.decorator import Registry

from .common import (
async_capture_events,
help_test_all,
import_and_test_deprecated_constant_enum,
)
from .common import async_capture_events


class MockFlowManager(data_entry_flow.FlowManager):
Expand Down Expand Up @@ -985,22 +981,6 @@ async def async_step_second(self, user_input=None):
assert len(manager.async_progress()) == 0


def test_all() -> None:
"""Test module.__all__ is correctly set."""
help_test_all(data_entry_flow)


@pytest.mark.parametrize(("enum"), list(data_entry_flow.FlowResultType))
def test_deprecated_constants(
caplog: pytest.LogCaptureFixture,
enum: data_entry_flow.FlowResultType,
) -> None:
"""Test deprecated constants."""
import_and_test_deprecated_constant_enum(
caplog, data_entry_flow, enum, "RESULT_TYPE_", "2025.1"
)


def test_section_in_serializer() -> None:
"""Test section with custom_serializer."""
assert cv.custom_serializer(
Expand Down

0 comments on commit a68cf21

Please sign in to comment.