mirror of
https://github.com/home-assistant/core
synced 2024-09-06 10:29:55 +02:00
Add typing to async_register_entity_service (#50015)
This commit is contained in:
parent
1ad9f1d714
commit
378cee01b4
@ -71,7 +71,7 @@ async def async_setup_entry(
|
||||
platform = entity_platform.current_platform.get()
|
||||
assert platform
|
||||
|
||||
platform.async_register_entity_service( # type: ignore
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_SET_LOCK_USERCODE,
|
||||
{
|
||||
vol.Required(ATTR_CODE_SLOT): vol.Coerce(int),
|
||||
@ -80,7 +80,7 @@ async def async_setup_entry(
|
||||
"async_set_lock_usercode",
|
||||
)
|
||||
|
||||
platform.async_register_entity_service( # type: ignore
|
||||
platform.async_register_entity_service(
|
||||
SERVICE_CLEAR_LOCK_USERCODE,
|
||||
{
|
||||
vol.Required(ATTR_CODE_SLOT): vol.Coerce(int),
|
||||
|
@ -862,17 +862,19 @@ ENTITY_SERVICE_FIELDS = {
|
||||
|
||||
def make_entity_service_schema(
|
||||
schema: dict, *, extra: int = vol.PREVENT_EXTRA
|
||||
) -> vol.All:
|
||||
) -> vol.Schema:
|
||||
"""Create an entity service schema."""
|
||||
return vol.All(
|
||||
vol.Schema(
|
||||
{
|
||||
**schema,
|
||||
**ENTITY_SERVICE_FIELDS,
|
||||
},
|
||||
extra=extra,
|
||||
),
|
||||
has_at_least_one_key(*ENTITY_SERVICE_FIELDS),
|
||||
return vol.Schema(
|
||||
vol.All(
|
||||
vol.Schema(
|
||||
{
|
||||
**schema,
|
||||
**ENTITY_SERVICE_FIELDS,
|
||||
},
|
||||
extra=extra,
|
||||
),
|
||||
has_at_least_one_key(*ENTITY_SERVICE_FIELDS),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
|
@ -8,9 +8,10 @@ from datetime import datetime, timedelta
|
||||
import logging
|
||||
from logging import Logger
|
||||
from types import ModuleType
|
||||
from typing import TYPE_CHECKING, Callable
|
||||
from typing import TYPE_CHECKING, Any, Callable
|
||||
|
||||
from typing_extensions import Protocol
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import (
|
||||
@ -625,7 +626,13 @@ class EntityPlatform:
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_register_entity_service(self, name, schema, func, required_features=None): # type: ignore[no-untyped-def]
|
||||
def async_register_entity_service(
|
||||
self,
|
||||
name: str,
|
||||
schema: dict | vol.Schema,
|
||||
func: str | Callable[..., Any],
|
||||
required_features: Iterable[int] | None = None,
|
||||
) -> None:
|
||||
"""Register an entity service.
|
||||
|
||||
Services will automatically be shared by all platforms of the same domain.
|
||||
|
Loading…
Reference in New Issue
Block a user