mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add decorator typing [modern_forms] (#107558)
This commit is contained in:
parent
fbbe03c93c
commit
e91a159efa
@ -1,8 +1,10 @@
|
||||
"""The Modern Forms integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable, Coroutine
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
from typing import Any, Concatenate, ParamSpec, TypeVar
|
||||
|
||||
from aiomodernforms import (
|
||||
ModernFormsConnectionError,
|
||||
@ -24,6 +26,11 @@ from homeassistant.helpers.update_coordinator import (
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
_ModernFormsDeviceEntityT = TypeVar(
|
||||
"_ModernFormsDeviceEntityT", bound="ModernFormsDeviceEntity"
|
||||
)
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=5)
|
||||
PLATFORMS = [
|
||||
Platform.BINARY_SENSOR,
|
||||
@ -64,14 +71,18 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
return unload_ok
|
||||
|
||||
|
||||
def modernforms_exception_handler(func):
|
||||
def modernforms_exception_handler(
|
||||
func: Callable[Concatenate[_ModernFormsDeviceEntityT, _P], Any],
|
||||
) -> Callable[Concatenate[_ModernFormsDeviceEntityT, _P], Coroutine[Any, Any, None]]:
|
||||
"""Decorate Modern Forms calls to handle Modern Forms exceptions.
|
||||
|
||||
A decorator that wraps the passed in function, catches Modern Forms errors,
|
||||
and handles the availability of the device in the data coordinator.
|
||||
"""
|
||||
|
||||
async def handler(self, *args, **kwargs):
|
||||
async def handler(
|
||||
self: _ModernFormsDeviceEntityT, *args: _P.args, **kwargs: _P.kwargs
|
||||
) -> None:
|
||||
try:
|
||||
await func(self, *args, **kwargs)
|
||||
self.coordinator.async_update_listeners()
|
||||
|
Loading…
x
Reference in New Issue
Block a user