Home Assistant Unofficial Reference 2024.12.1
util.py
Go to the documentation of this file.
1 """Utilities for Evil Genius Labs."""
2 
3 from __future__ import annotations
4 
5 from collections.abc import Awaitable, Callable, Coroutine
6 from functools import wraps
7 from typing import Any, Concatenate
8 
9 from .entity import EvilGeniusEntity
10 
11 
12 def update_when_done[_EvilGeniusEntityT: EvilGeniusEntity, **_P, _R](
13  func: Callable[Concatenate[_EvilGeniusEntityT, _P], Awaitable[_R]],
14 ) -> Callable[Concatenate[_EvilGeniusEntityT, _P], Coroutine[Any, Any, _R]]:
15  """Decorate function to trigger update when function is done."""
16 
17  @wraps(func)
18  async def wrapper(
19  self: _EvilGeniusEntityT, *args: _P.args, **kwargs: _P.kwargs
20  ) -> _R:
21  """Wrap function."""
22  result = await func(self, *args, **kwargs)
23  await self.coordinator.async_request_refresh()
24  return result
25 
26  return wrapper