mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Improve hassio decorator typing (#110545)
* Improve hassio decorator typing * Fix typing
This commit is contained in:
parent
0bbe46d236
commit
269f6be096
@ -2,11 +2,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from collections.abc import Coroutine
|
||||
from collections.abc import Callable, Coroutine
|
||||
from http import HTTPStatus
|
||||
import logging
|
||||
import os
|
||||
from typing import Any
|
||||
from typing import Any, ParamSpec
|
||||
|
||||
import aiohttp
|
||||
from yarl import URL
|
||||
@ -23,6 +23,8 @@ from homeassistant.loader import bind_hass
|
||||
|
||||
from .const import ATTR_DISCOVERY, DOMAIN, X_HASS_SOURCE
|
||||
|
||||
_P = ParamSpec("_P")
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -30,10 +32,12 @@ class HassioAPIError(RuntimeError):
|
||||
"""Return if a API trow a error."""
|
||||
|
||||
|
||||
def _api_bool(funct):
|
||||
def _api_bool(
|
||||
funct: Callable[_P, Coroutine[Any, Any, dict[str, Any]]],
|
||||
) -> Callable[_P, Coroutine[Any, Any, bool]]:
|
||||
"""Return a boolean."""
|
||||
|
||||
async def _wrapper(*argv, **kwargs):
|
||||
async def _wrapper(*argv: _P.args, **kwargs: _P.kwargs) -> bool:
|
||||
"""Wrap function."""
|
||||
try:
|
||||
data = await funct(*argv, **kwargs)
|
||||
@ -44,10 +48,12 @@ def _api_bool(funct):
|
||||
return _wrapper
|
||||
|
||||
|
||||
def api_data(funct):
|
||||
def api_data(
|
||||
funct: Callable[_P, Coroutine[Any, Any, dict[str, Any]]],
|
||||
) -> Callable[_P, Coroutine[Any, Any, Any]]:
|
||||
"""Return data of an api."""
|
||||
|
||||
async def _wrapper(*argv, **kwargs):
|
||||
async def _wrapper(*argv: _P.args, **kwargs: _P.kwargs) -> Any:
|
||||
"""Wrap function."""
|
||||
data = await funct(*argv, **kwargs)
|
||||
if data["result"] == "ok":
|
||||
@ -80,7 +86,7 @@ async def async_get_addon_store_info(hass: HomeAssistant, slug: str) -> dict:
|
||||
|
||||
|
||||
@bind_hass
|
||||
async def async_update_diagnostics(hass: HomeAssistant, diagnostics: bool) -> dict:
|
||||
async def async_update_diagnostics(hass: HomeAssistant, diagnostics: bool) -> bool:
|
||||
"""Update Supervisor diagnostics toggle.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
@ -255,7 +261,7 @@ async def async_update_core(
|
||||
|
||||
@bind_hass
|
||||
@_api_bool
|
||||
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> bool:
|
||||
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> dict:
|
||||
"""Apply a suggestion from supervisor's resolution center.
|
||||
|
||||
The caller of the function should handle HassioAPIError.
|
||||
|
Loading…
x
Reference in New Issue
Block a user