Skip to content

Commit

Permalink
Add APIRequestProtocol for APIfactory.request (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinHjelmare authored Jun 23, 2022
1 parent 9758328 commit b61737b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions pytradfri/api/aiocoap_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import Enum
import json
import logging
from typing import Any, Dict, List, Union, cast, overload
from typing import Any, Dict, List, Protocol, Union, cast, overload

from aiocoap import Context, Message
from aiocoap.credentials import CredentialsMissingError
Expand Down Expand Up @@ -35,6 +35,27 @@ class UndefinedType(Enum):
_SENTINEL = UndefinedType._singleton # pylint: disable=protected-access


class APIRequestProtocol(Protocol):
"""Represent the protocol for the APIFactory request method."""

@overload
async def __call__(
self, api_commands: Command[T], timeout: float | None = None
) -> T:
"""Define the signature of the request method."""

@overload
async def __call__(
self, api_commands: list[Command[T]], timeout: float | None = None
) -> list[T]:
"""Define the signature of the request method."""

async def __call__(
self, api_commands: Command[T] | list[Command[T]], timeout: float | None = None
) -> T | list[T]:
"""Define the signature of the request method."""


class APIFactory:
"""ApiFactory."""

Expand Down Expand Up @@ -195,14 +216,12 @@ async def request(
self, api_commands: Command[T], timeout: float | None = None
) -> T:
"""Make a request."""
...

@overload
async def request(
self, api_commands: list[Command[T]], timeout: float | None = None
) -> list[T]:
"""Make a request."""
...

async def request(
self, api_commands: Command[T] | list[Command[T]], timeout: float | None = None
Expand Down

0 comments on commit b61737b

Please sign in to comment.