Type decora error decorator (#70977)

This commit is contained in:
Marc Mueller 2022-04-28 21:03:37 +02:00 committed by GitHub
parent 1eb5316d89
commit 7fefd4bc67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -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()