From 7fefd4bc675550952884337b6405b67256aeab4f Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Thu, 28 Apr 2022 21:03:37 +0200 Subject: [PATCH] Type decora error decorator (#70977) --- homeassistant/components/decora/light.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/decora/light.py b/homeassistant/components/decora/light.py index b43881c39b9..9dbc031d476 100644 --- a/homeassistant/components/decora/light.py +++ b/homeassistant/components/decora/light.py @@ -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()