mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Use PEP 695 for decorator typing with type aliases in esphome (#124234)
This commit is contained in:
parent
89728f41e1
commit
69652ca2ca
@ -5,7 +5,7 @@ from __future__ import annotations
|
|||||||
from collections.abc import Awaitable, Callable, Coroutine
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
import functools
|
import functools
|
||||||
import math
|
import math
|
||||||
from typing import TYPE_CHECKING, Any, Concatenate, Generic, ParamSpec, TypeVar, cast
|
from typing import TYPE_CHECKING, Any, Concatenate, Generic, TypeVar, cast
|
||||||
|
|
||||||
from aioesphomeapi import (
|
from aioesphomeapi import (
|
||||||
APIConnectionError,
|
APIConnectionError,
|
||||||
@ -30,8 +30,6 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|||||||
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
from .entry_data import ESPHomeConfigEntry, RuntimeEntryData
|
||||||
from .enum_mapper import EsphomeEnumMapper
|
from .enum_mapper import EsphomeEnumMapper
|
||||||
|
|
||||||
_R = TypeVar("_R")
|
|
||||||
_P = ParamSpec("_P")
|
|
||||||
_InfoT = TypeVar("_InfoT", bound=EntityInfo)
|
_InfoT = TypeVar("_InfoT", bound=EntityInfo)
|
||||||
_EntityT = TypeVar("_EntityT", bound="EsphomeEntity[Any,Any]")
|
_EntityT = TypeVar("_EntityT", bound="EsphomeEntity[Any,Any]")
|
||||||
_StateT = TypeVar("_StateT", bound=EntityState)
|
_StateT = TypeVar("_StateT", bound=EntityState)
|
||||||
@ -116,7 +114,7 @@ async def platform_async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def esphome_state_property(
|
def esphome_state_property[_R, _EntityT: EsphomeEntity[Any, Any]](
|
||||||
func: Callable[[_EntityT], _R],
|
func: Callable[[_EntityT], _R],
|
||||||
) -> Callable[[_EntityT], _R | None]:
|
) -> Callable[[_EntityT], _R | None]:
|
||||||
"""Wrap a state property of an esphome entity.
|
"""Wrap a state property of an esphome entity.
|
||||||
@ -139,7 +137,7 @@ def esphome_state_property(
|
|||||||
return _wrapper
|
return _wrapper
|
||||||
|
|
||||||
|
|
||||||
def convert_api_error_ha_error(
|
def convert_api_error_ha_error[**_P, _R, _EntityT: EsphomeEntity[Any, Any]](
|
||||||
func: Callable[Concatenate[_EntityT, _P], Awaitable[None]],
|
func: Callable[Concatenate[_EntityT, _P], Awaitable[None]],
|
||||||
) -> Callable[Concatenate[_EntityT, _P], Coroutine[Any, Any, None]]:
|
) -> Callable[Concatenate[_EntityT, _P], Coroutine[Any, Any, None]]:
|
||||||
"""Decorate ESPHome command calls that send commands/make changes to the device.
|
"""Decorate ESPHome command calls that send commands/make changes to the device.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user