Skip to content

Commit

Permalink
Improve husqvarna_automower decorator typing (#133047)
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Dec 12, 2024
1 parent c18cbf5 commit 2e133df
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions homeassistant/components/husqvarna_automower/entity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
"""Platform for Husqvarna Automower base entity."""

from __future__ import annotations

import asyncio
from collections.abc import Awaitable, Callable, Coroutine
from collections.abc import Callable, Coroutine
import functools
import logging
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Concatenate

from aioautomower.exceptions import ApiException
from aioautomower.model import MowerActivities, MowerAttributes, MowerStates, WorkArea
Expand Down Expand Up @@ -52,18 +54,17 @@ def _work_area_translation_key(work_area_id: int, key: str) -> str:
return f"work_area_{key}"


def handle_sending_exception(
type _FuncType[_T, **_P, _R] = Callable[Concatenate[_T, _P], Coroutine[Any, Any, _R]]


def handle_sending_exception[_Entity: AutomowerBaseEntity, **_P](
poll_after_sending: bool = False,
) -> Callable[
[Callable[..., Awaitable[Any]]], Callable[..., Coroutine[Any, Any, None]]
]:
) -> Callable[[_FuncType[_Entity, _P, Any]], _FuncType[_Entity, _P, None]]:
"""Handle exceptions while sending a command and optionally refresh coordinator."""

def decorator(
func: Callable[..., Awaitable[Any]],
) -> Callable[..., Coroutine[Any, Any, None]]:
def decorator(func: _FuncType[_Entity, _P, Any]) -> _FuncType[_Entity, _P, None]:
@functools.wraps(func)
async def wrapper(self: Any, *args: Any, **kwargs: Any) -> Any:
async def wrapper(self: _Entity, *args: _P.args, **kwargs: _P.kwargs) -> None:
try:
await func(self, *args, **kwargs)
except ApiException as exception:
Expand Down

0 comments on commit 2e133df

Please sign in to comment.