mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add decorator typing [izone] (#107556)
This commit is contained in:
parent
68ddc1481e
commit
bec88e5e51
@ -1,9 +1,9 @@
|
||||
"""Support for the iZone HVAC."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
from collections.abc import Callable, Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
from typing import Any, Concatenate, ParamSpec, TypeVar
|
||||
|
||||
from pizone import Controller, Zone
|
||||
import voluptuous as vol
|
||||
@ -47,6 +47,12 @@ from .const import (
|
||||
IZONE,
|
||||
)
|
||||
|
||||
_DeviceT = TypeVar("_DeviceT", bound="ControllerDevice | ZoneDevice")
|
||||
_T = TypeVar("_T")
|
||||
_R = TypeVar("_R")
|
||||
_P = ParamSpec("_P")
|
||||
_FuncType = Callable[Concatenate[_T, _P], _R]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
_IZONE_FAN_TO_HA = {
|
||||
@ -112,13 +118,15 @@ async def async_setup_entry(
|
||||
)
|
||||
|
||||
|
||||
def _return_on_connection_error(ret=None):
|
||||
def wrap(func):
|
||||
def wrapped_f(*args, **kwargs):
|
||||
if not args[0].available:
|
||||
def _return_on_connection_error(
|
||||
ret: _T = None, # type: ignore[assignment]
|
||||
) -> Callable[[_FuncType[_DeviceT, _P, _R]], _FuncType[_DeviceT, _P, _R | _T]]:
|
||||
def wrap(func: _FuncType[_DeviceT, _P, _R]) -> _FuncType[_DeviceT, _P, _R | _T]:
|
||||
def wrapped_f(self: _DeviceT, *args: _P.args, **kwargs: _P.kwargs) -> _R | _T:
|
||||
if not self.available:
|
||||
return ret
|
||||
try:
|
||||
return func(*args, **kwargs)
|
||||
return func(self, *args, **kwargs)
|
||||
except ConnectionError:
|
||||
return ret
|
||||
|
||||
@ -498,7 +506,7 @@ class ZoneDevice(ClimateEntity):
|
||||
return self._controller.available
|
||||
|
||||
@property
|
||||
@_return_on_connection_error(0)
|
||||
@_return_on_connection_error(ClimateEntityFeature(0))
|
||||
def supported_features(self) -> ClimateEntityFeature:
|
||||
"""Return the list of supported features."""
|
||||
if self._zone.mode == Zone.Mode.AUTO:
|
||||
|
Loading…
x
Reference in New Issue
Block a user