From b4eee166aa820626119ebff590a90a0f034ca766 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 25 Jun 2024 11:58:27 +0200 Subject: [PATCH] Add voluptuous type aliases (#120399) --- homeassistant/core.py | 8 ++++---- homeassistant/helpers/entity_component.py | 7 +++---- homeassistant/helpers/entity_platform.py | 6 ++---- homeassistant/helpers/typing.py | 4 ++++ 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/homeassistant/core.py b/homeassistant/core.py index ac287fb2d5f..f114049b2b2 100644 --- a/homeassistant/core.py +++ b/homeassistant/core.py @@ -96,7 +96,7 @@ from .helpers.deprecation import ( dir_with_deprecated_constants, ) from .helpers.json import json_bytes, json_fragment -from .helpers.typing import UNDEFINED, UndefinedType +from .helpers.typing import UNDEFINED, UndefinedType, VolSchemaType from .util import dt as dt_util, location from .util.async_ import ( cancelling, @@ -2355,7 +2355,7 @@ class Service: | EntityServiceResponse | None, ], - schema: vol.Schema | None, + schema: VolSchemaType | None, domain: str, service: str, context: Context | None = None, @@ -2503,7 +2503,7 @@ class ServiceRegistry: | EntityServiceResponse | None, ], - schema: vol.Schema | None = None, + schema: VolSchemaType | None = None, supports_response: SupportsResponse = SupportsResponse.NONE, job_type: HassJobType | None = None, ) -> None: @@ -2530,7 +2530,7 @@ class ServiceRegistry: | EntityServiceResponse | None, ], - schema: vol.Schema | None = None, + schema: VolSchemaType | None = None, supports_response: SupportsResponse = SupportsResponse.NONE, job_type: HassJobType | None = None, ) -> None: diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index aae0e2058e4..0034eb1c6fc 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -11,7 +11,6 @@ from types import ModuleType from typing import Any, Generic from typing_extensions import TypeVar -import voluptuous as vol from homeassistant import config as conf_util from homeassistant.config_entries import ConfigEntry @@ -36,7 +35,7 @@ from homeassistant.setup import async_prepare_setup_platform from . import config_validation as cv, discovery, entity, service from .entity_platform import EntityPlatform -from .typing import ConfigType, DiscoveryInfoType +from .typing import ConfigType, DiscoveryInfoType, VolDictType, VolSchemaType DEFAULT_SCAN_INTERVAL = timedelta(seconds=15) DATA_INSTANCES = "entity_components" @@ -222,7 +221,7 @@ class EntityComponent(Generic[_EntityT]): def async_register_legacy_entity_service( self, name: str, - schema: dict[str | vol.Marker, Any] | vol.Schema, + schema: VolDictType | VolSchemaType, func: str | Callable[..., Any], required_features: list[int] | None = None, supports_response: SupportsResponse = SupportsResponse.NONE, @@ -259,7 +258,7 @@ class EntityComponent(Generic[_EntityT]): def async_register_entity_service( self, name: str, - schema: dict[str | vol.Marker, Any] | vol.Schema, + schema: VolDictType | VolSchemaType, func: str | Callable[..., Any], required_features: list[int] | None = None, supports_response: SupportsResponse = SupportsResponse.NONE, diff --git a/homeassistant/helpers/entity_platform.py b/homeassistant/helpers/entity_platform.py index 4dbe3ac68d8..6774780f00f 100644 --- a/homeassistant/helpers/entity_platform.py +++ b/homeassistant/helpers/entity_platform.py @@ -10,8 +10,6 @@ from functools import partial from logging import Logger, getLogger from typing import TYPE_CHECKING, Any, Protocol -import voluptuous as vol - from homeassistant import config_entries from homeassistant.const import ( ATTR_RESTORED, @@ -52,7 +50,7 @@ from . import ( from .entity_registry import EntityRegistry, RegistryEntryDisabler, RegistryEntryHider from .event import async_call_later from .issue_registry import IssueSeverity, async_create_issue -from .typing import UNDEFINED, ConfigType, DiscoveryInfoType +from .typing import UNDEFINED, ConfigType, DiscoveryInfoType, VolDictType, VolSchemaType if TYPE_CHECKING: from .entity import Entity @@ -987,7 +985,7 @@ class EntityPlatform: def async_register_entity_service( self, name: str, - schema: dict[str | vol.Marker, Any] | vol.Schema, + schema: VolDictType | VolSchemaType, func: str | Callable[..., Any], required_features: Iterable[int] | None = None, supports_response: SupportsResponse = SupportsResponse.NONE, diff --git a/homeassistant/helpers/typing.py b/homeassistant/helpers/typing.py index 3cdd9ec9250..65774a0b168 100644 --- a/homeassistant/helpers/typing.py +++ b/homeassistant/helpers/typing.py @@ -5,6 +5,8 @@ from enum import Enum from functools import partial from typing import Any, Never +import voluptuous as vol + from .deprecation import ( DeferredDeprecatedAlias, all_with_deprecated_constants, @@ -19,6 +21,8 @@ type ServiceDataType = dict[str, Any] type StateType = str | int | float | None type TemplateVarsType = Mapping[str, Any] | None type NoEventData = Mapping[str, Never] +type VolSchemaType = vol.Schema | vol.All | vol.Any +type VolDictType = dict[str | vol.Marker, Any] # Custom type for recorder Queries type QueryType = Any