From 827a1b1f48fc54c0f19fddbd6f4eb98597f6aa44 Mon Sep 17 00:00:00 2001
From: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Date: Fri, 12 Jan 2024 11:32:03 +0100
Subject: [PATCH] Add decorator typing [homematicip_cloud] (#107555)

---
 .../components/homematicip_cloud/helpers.py   | 22 +++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/homeassistant/components/homematicip_cloud/helpers.py b/homeassistant/components/homematicip_cloud/helpers.py
index 1680904bbca..4647e553382 100644
--- a/homeassistant/components/homematicip_cloud/helpers.py
+++ b/homeassistant/components/homematicip_cloud/helpers.py
@@ -1,17 +1,25 @@
 """Helper functions for Homematicip Cloud Integration."""
+from __future__ import annotations
 
+from collections.abc import Callable, Coroutine
 from functools import wraps
 import json
 import logging
+from typing import Any, Concatenate, ParamSpec, TypeGuard, TypeVar
 
 from homeassistant.exceptions import HomeAssistantError
 
 from . import HomematicipGenericEntity
 
+_HomematicipGenericEntityT = TypeVar(
+    "_HomematicipGenericEntityT", bound=HomematicipGenericEntity
+)
+_P = ParamSpec("_P")
+
 _LOGGER = logging.getLogger(__name__)
 
 
-def is_error_response(response) -> bool:
+def is_error_response(response: Any) -> TypeGuard[dict[str, Any]]:
     """Response from async call contains errors or not."""
     if isinstance(response, dict):
         return response.get("errorCode") not in ("", None)
@@ -19,13 +27,19 @@ def is_error_response(response) -> bool:
     return False
 
 
-def handle_errors(func):
+def handle_errors(
+    func: Callable[
+        Concatenate[_HomematicipGenericEntityT, _P], Coroutine[Any, Any, Any]
+    ],
+) -> Callable[Concatenate[_HomematicipGenericEntityT, _P], Coroutine[Any, Any, Any]]:
     """Handle async errors."""
 
     @wraps(func)
-    async def inner(self: HomematicipGenericEntity) -> None:
+    async def inner(
+        self: _HomematicipGenericEntityT, *args: _P.args, **kwargs: _P.kwargs
+    ) -> None:
         """Handle errors from async call."""
-        result = await func(self)
+        result = await func(self, *args, **kwargs)
         if is_error_response(result):
             _LOGGER.error(
                 "Error while execute function %s: %s",