mirror of https://github.com/home-assistant/core
Type decora error decorator (#70977)
This commit is contained in:
parent
1eb5316d89
commit
7fefd4bc67
|
@ -1,13 +1,16 @@
|
|||
"""Support for Decora dimmers."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import copy
|
||||
from functools import wraps
|
||||
import logging
|
||||
import time
|
||||
from typing import TypeVar
|
||||
|
||||
from bluepy.btle import BTLEException # pylint: disable=import-error
|
||||
import decora # pylint: disable=import-error
|
||||
from typing_extensions import Concatenate, ParamSpec
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import util
|
||||
|
@ -23,6 +26,10 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
_DecoraLightT = TypeVar("_DecoraLightT", bound="DecoraLight")
|
||||
_R = TypeVar("_R")
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -50,11 +57,15 @@ PLATFORM_SCHEMA = vol.Schema(
|
|||
)
|
||||
|
||||
|
||||
def retry(method):
|
||||
def retry(
|
||||
method: Callable[Concatenate[_DecoraLightT, _P], _R]
|
||||
) -> Callable[Concatenate[_DecoraLightT, _P], _R | None]:
|
||||
"""Retry bluetooth commands."""
|
||||
|
||||
@wraps(method)
|
||||
def wrapper_retry(device, *args, **kwargs):
|
||||
def wrapper_retry(
|
||||
device: _DecoraLightT, *args: _P.args, **kwargs: _P.kwargs
|
||||
) -> _R | None:
|
||||
"""Try send command and retry on error."""
|
||||
|
||||
initial = time.monotonic()
|
||||
|
|
Loading…
Reference in New Issue