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