mirror of
https://github.com/home-assistant/core.git
synced 2025-08-05 13:45:12 +02:00
Type decora error decorator (#70977)
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
"""Support for Decora dimmers."""
|
"""Support for Decora dimmers."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from collections.abc import Callable
|
||||||
import copy
|
import copy
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
from typing import TypeVar
|
||||||
|
|
||||||
from bluepy.btle import BTLEException # pylint: disable=import-error
|
from bluepy.btle import BTLEException # pylint: disable=import-error
|
||||||
import decora # pylint: disable=import-error
|
import decora # pylint: disable=import-error
|
||||||
|
from typing_extensions import Concatenate, ParamSpec
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import util
|
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.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
|
_DecoraLightT = TypeVar("_DecoraLightT", bound="DecoraLight")
|
||||||
|
_R = TypeVar("_R")
|
||||||
|
_P = ParamSpec("_P")
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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."""
|
"""Retry bluetooth commands."""
|
||||||
|
|
||||||
@wraps(method)
|
@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."""
|
"""Try send command and retry on error."""
|
||||||
|
|
||||||
initial = time.monotonic()
|
initial = time.monotonic()
|
||||||
|
Reference in New Issue
Block a user