From 62fd692d2704715adf0514b1e626576a9cc54720 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 25 Jun 2024 12:48:00 +0200 Subject: [PATCH] Improve async_register_admin_service schema typing (#120405) --- homeassistant/components/zha/websocket_api.py | 5 +++-- homeassistant/helpers/service.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zha/websocket_api.py b/homeassistant/components/zha/websocket_api.py index 1a51a06243e..cb95e930b1a 100644 --- a/homeassistant/components/zha/websocket_api.py +++ b/homeassistant/components/zha/websocket_api.py @@ -21,6 +21,7 @@ from homeassistant.helpers import entity_registry as er import homeassistant.helpers.config_validation as cv from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.service import async_register_admin_service +from homeassistant.helpers.typing import VolDictType, VolSchemaType from .api import ( async_change_channel, @@ -126,7 +127,7 @@ def _ensure_list_if_present[_T](value: _T | None) -> list[_T] | list[Any] | None return cast("list[_T]", value) if isinstance(value, list) else [value] -SERVICE_PERMIT_PARAMS = { +SERVICE_PERMIT_PARAMS: VolDictType = { vol.Optional(ATTR_IEEE): IEEE_SCHEMA, vol.Optional(ATTR_DURATION, default=60): vol.All( vol.Coerce(int), vol.Range(0, 254) @@ -138,7 +139,7 @@ SERVICE_PERMIT_PARAMS = { vol.Exclusive(ATTR_QR_CODE, "install_code"): vol.All(cv.string, qr_to_install_code), } -SERVICE_SCHEMAS = { +SERVICE_SCHEMAS: dict[str, VolSchemaType] = { SERVICE_PERMIT: vol.Schema( vol.All( cv.deprecated(ATTR_IEEE_ADDRESS, replacement_key=ATTR_IEEE), diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index a9959902084..22f5e7f8710 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -63,7 +63,7 @@ from . import ( ) from .group import expand_entity_ids from .selector import TargetSelector -from .typing import ConfigType, TemplateVarsType +from .typing import ConfigType, TemplateVarsType, VolSchemaType if TYPE_CHECKING: from .entity import Entity @@ -1100,7 +1100,7 @@ def async_register_admin_service( domain: str, service: str, service_func: Callable[[ServiceCall], Awaitable[None] | None], - schema: vol.Schema = vol.Schema({}, extra=vol.PREVENT_EXTRA), + schema: VolSchemaType = vol.Schema({}, extra=vol.PREVENT_EXTRA), ) -> None: """Register a service that requires admin access.""" hass.services.async_register(