hass-core/homeassistant/components/evil_genius_labs/util.py
Ville Skyttä 24b1e01d71
Update Ruff to 0.1.8, avoid linter/formatter conflicts (#106080)
* Disable Ruff rules that may conflict with the formatter

* Upgrade Ruff to 0.1.8

- https://github.com/astral-sh/ruff/releases/tag/v0.1.7
- https://github.com/astral-sh/ruff/releases/tag/v0.1.8

* Format with Ruff 0.1.8
2023-12-20 23:55:09 +01:00

29 lines
908 B
Python

"""Utilities for Evil Genius Labs."""
from __future__ import annotations
from collections.abc import Awaitable, Callable, Coroutine
from functools import wraps
from typing import Any, Concatenate, ParamSpec, TypeVar
from . import EvilGeniusEntity
_EvilGeniusEntityT = TypeVar("_EvilGeniusEntityT", bound=EvilGeniusEntity)
_R = TypeVar("_R")
_P = ParamSpec("_P")
def update_when_done(
func: Callable[Concatenate[_EvilGeniusEntityT, _P], Awaitable[_R]],
) -> Callable[Concatenate[_EvilGeniusEntityT, _P], Coroutine[Any, Any, _R]]:
"""Decorate function to trigger update when function is done."""
@wraps(func)
async def wrapper(
self: _EvilGeniusEntityT, *args: _P.args, **kwargs: _P.kwargs
) -> _R:
"""Wrap function."""
result = await func(self, *args, **kwargs)
await self.coordinator.async_request_refresh()
return result
return wrapper