mirror of
https://github.com/home-assistant/core.git
synced 2025-07-20 03:37:07 +00:00
Improve decorator type annotations (#104821)
This commit is contained in:
parent
4bc1e5075a
commit
d597cfec49
@ -2,9 +2,9 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Awaitable, Callable, Coroutine
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from aioguardian import Client
|
from aioguardian import Client
|
||||||
from aioguardian.errors import GuardianError
|
from aioguardian.errors import GuardianError
|
||||||
@ -170,7 +170,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def call_with_data(func: Callable) -> Callable:
|
def call_with_data(
|
||||||
|
func: Callable[[ServiceCall, GuardianData], Coroutine[Any, Any, None]]
|
||||||
|
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
|
||||||
"""Hydrate a service call with the appropriate GuardianData object."""
|
"""Hydrate a service call with the appropriate GuardianData object."""
|
||||||
|
|
||||||
async def wrapper(call: ServiceCall) -> None:
|
async def wrapper(call: ServiceCall) -> None:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Awaitable, Callable
|
from collections.abc import Callable, Coroutine
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from functools import partial, wraps
|
from functools import partial, wraps
|
||||||
@ -326,10 +326,17 @@ async def async_setup_entry( # noqa: C901
|
|||||||
|
|
||||||
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
|
entry.async_on_unload(entry.add_update_listener(async_reload_entry))
|
||||||
|
|
||||||
def call_with_controller(update_programs_and_zones: bool = True) -> Callable:
|
def call_with_controller(
|
||||||
|
update_programs_and_zones: bool = True,
|
||||||
|
) -> Callable[
|
||||||
|
[Callable[[ServiceCall, Controller], Coroutine[Any, Any, None]]],
|
||||||
|
Callable[[ServiceCall], Coroutine[Any, Any, None]],
|
||||||
|
]:
|
||||||
"""Hydrate a service call with the appropriate controller."""
|
"""Hydrate a service call with the appropriate controller."""
|
||||||
|
|
||||||
def decorator(func: Callable) -> Callable[..., Awaitable]:
|
def decorator(
|
||||||
|
func: Callable[[ServiceCall, Controller], Coroutine[Any, Any, None]]
|
||||||
|
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
|
||||||
"""Define the decorator."""
|
"""Define the decorator."""
|
||||||
|
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections.abc import Callable, Iterable
|
from collections.abc import Callable, Coroutine, Iterable
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
@ -336,7 +336,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def extract_system(func: Callable) -> Callable:
|
def extract_system(
|
||||||
|
func: Callable[[ServiceCall, SystemType], Coroutine[Any, Any, None]]
|
||||||
|
) -> Callable[[ServiceCall], Coroutine[Any, Any, None]]:
|
||||||
"""Define a decorator to get the correct system for a service call."""
|
"""Define a decorator to get the correct system for a service call."""
|
||||||
|
|
||||||
async def wrapper(call: ServiceCall) -> None:
|
async def wrapper(call: ServiceCall) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user