Skip to content

Commit

Permalink
Set "from __future__ import annotations" as required import (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Jan 26, 2024
1 parent ddde659 commit 95bb092
Show file tree
Hide file tree
Showing 120 changed files with 532 additions and 174 deletions.
8 changes: 6 additions & 2 deletions deebot_client/api_client.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Api client module."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.hardware.deebot import get_static_device_info

from .authentication import Authenticator
from .const import PATH_API_APPSVR_APP, PATH_API_PIM_PRODUCT_IOT_MAP
from .exceptions import ApiError
from .logging_filter import get_logger
from .models import ApiDeviceInfo, DeviceInfo

if TYPE_CHECKING:
from .authentication import Authenticator

_LOGGER = get_logger(__name__)


Expand Down
8 changes: 6 additions & 2 deletions deebot_client/authentication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""Authentication module."""
from __future__ import annotations

import asyncio
from collections.abc import Callable, Coroutine, Mapping
from http import HTTPStatus
import time
from typing import Any
from typing import TYPE_CHECKING, Any
from urllib.parse import urljoin

from aiohttp import ClientResponseError, hdrs
Expand All @@ -14,6 +15,9 @@
from .models import Configuration, Credentials
from .util import cancel, create_task, md5

if TYPE_CHECKING:
from collections.abc import Callable, Coroutine, Mapping

_LOGGER = get_logger(__name__)

_CLIENT_KEY = "1520391301804"
Expand Down
14 changes: 9 additions & 5 deletions deebot_client/capabilities.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Device capabilities module."""
from collections.abc import Callable
from __future__ import annotations

from dataclasses import dataclass, field, fields, is_dataclass
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Generic, TypeVar

from deebot_client.command import Command, SetCommand
from deebot_client.events import (
AdvancedModeEvent,
AvailabilityEvent,
Expand Down Expand Up @@ -41,19 +41,23 @@
WorkMode,
WorkModeEvent,
)
from deebot_client.events.efficiency_mode import EfficiencyMode, EfficiencyModeEvent
from deebot_client.models import CleanAction, CleanMode

if TYPE_CHECKING:
from collections.abc import Callable

from _typeshed import DataclassInstance

from deebot_client.command import Command, SetCommand
from deebot_client.events.efficiency_mode import EfficiencyMode, EfficiencyModeEvent
from deebot_client.models import CleanAction, CleanMode


_T = TypeVar("_T")
_EVENT = TypeVar("_EVENT", bound=Event)


def _get_events(
capabilities: "DataclassInstance",
capabilities: DataclassInstance,
) -> MappingProxyType[type[Event], list[Command]]:
events = {}
for field_ in fields(capabilities):
Expand Down
23 changes: 14 additions & 9 deletions deebot_client/command.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
"""Base command."""
from __future__ import annotations

from abc import ABC, abstractmethod
import asyncio
from dataclasses import dataclass, field
from types import MappingProxyType
from typing import Any, final
from typing import TYPE_CHECKING, Any, final

from deebot_client.events import AvailabilityEvent
from deebot_client.exceptions import DeebotError

from .authentication import Authenticator
from .const import PATH_API_IOT_DEVMANAGER, REQUEST_HEADERS, DataType
from .event_bus import EventBus
from .logging_filter import get_logger
from .message import HandlingResult, HandlingState, Message
from .models import DeviceInfo

if TYPE_CHECKING:
from types import MappingProxyType

from .authentication import Authenticator
from .event_bus import EventBus
from .models import DeviceInfo

_LOGGER = get_logger(__name__)

Expand All @@ -22,15 +27,15 @@
class CommandResult(HandlingResult):
"""Command result object."""

requested_commands: list["Command"] = field(default_factory=list)
requested_commands: list[Command] = field(default_factory=list)

@classmethod
def success(cls) -> "CommandResult":
def success(cls) -> CommandResult:
"""Create result with handling success."""
return CommandResult(HandlingState.SUCCESS)

@classmethod
def analyse(cls) -> "CommandResult":
def analyse(cls) -> CommandResult:
"""Create result with handling analyse."""
return CommandResult(HandlingState.ANALYSE)

Expand Down Expand Up @@ -252,7 +257,7 @@ def handle_mqtt_p2p(self, event_bus: EventBus, response: dict[str, Any]) -> None
"""Handle response received over the mqtt channel "p2p"."""

@classmethod
def create_from_mqtt(cls, data: dict[str, Any]) -> "CommandMqttP2P":
def create_from_mqtt(cls, data: dict[str, Any]) -> CommandMqttP2P:
"""Create a command from the mqtt data."""
values: dict[str, Any] = {}
if not hasattr(cls, "_mqtt_params"):
Expand Down
8 changes: 7 additions & 1 deletion deebot_client/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"""Commands module."""
from deebot_client.command import Command, CommandMqttP2P
from __future__ import annotations

from typing import TYPE_CHECKING

from deebot_client.const import DataType

from .json import (
COMMANDS as JSON_COMMANDS,
COMMANDS_WITH_MQTT_P2P_HANDLING as JSON_COMMANDS_WITH_MQTT_P2P_HANDLING,
)

if TYPE_CHECKING:
from deebot_client.command import Command, CommandMqttP2P

COMMANDS: dict[DataType, dict[str, type[Command]]] = {DataType.JSON: JSON_COMMANDS}

COMMANDS_WITH_MQTT_P2P_HANDLING: dict[DataType, dict[str, type[CommandMqttP2P]]] = {
Expand Down
8 changes: 7 additions & 1 deletion deebot_client/commands/json/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""Json commands module."""
from __future__ import annotations

from typing import TYPE_CHECKING

from deebot_client.command import Command, CommandMqttP2P

from .advanced_mode import GetAdvancedMode, SetAdvancedMode
Expand All @@ -10,7 +14,6 @@
from .clean_count import GetCleanCount, SetCleanCount
from .clean_logs import GetCleanLogs
from .clean_preference import GetCleanPreference, SetCleanPreference
from .common import JsonCommand
from .continuous_cleaning import GetContinuousCleaning, SetContinuousCleaning
from .efficiency import GetEfficiencyMode, SetEfficiencyMode
from .error import GetError
Expand All @@ -36,6 +39,9 @@
from .water_info import GetWaterInfo, SetWaterInfo
from .work_mode import GetWorkMode, SetWorkMode

if TYPE_CHECKING:
from .common import JsonCommand

__all__ = [
"GetAdvancedMode",
"SetAdvancedMode",
Expand Down
1 change: 1 addition & 0 deletions deebot_client/commands/json/advanced_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Advanced mode command module."""
from __future__ import annotations

from deebot_client.events import AdvancedModeEvent

Expand Down
2 changes: 2 additions & 0 deletions deebot_client/commands/json/battery.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Battery commands."""
from __future__ import annotations

from deebot_client.messages.json import OnBattery

from .common import JsonCommandWithMessageHandling
Expand Down
1 change: 1 addition & 0 deletions deebot_client/commands/json/carpet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Carpet pressure command module."""
from __future__ import annotations

from deebot_client.events import CarpetAutoFanBoostEvent

Expand Down
8 changes: 6 additions & 2 deletions deebot_client/commands/json/charge.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Charge commands."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.event_bus import EventBus
from deebot_client.events import StateEvent
from deebot_client.logging_filter import get_logger
from deebot_client.message import HandlingResult
Expand All @@ -10,6 +11,9 @@
from .common import ExecuteCommand
from .const import CODE

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus

_LOGGER = get_logger(__name__)


Expand Down
8 changes: 6 additions & 2 deletions deebot_client/commands/json/charge_state.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Charge state commands."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.event_bus import EventBus
from deebot_client.events import StateEvent
from deebot_client.message import HandlingResult, MessageBodyDataDict
from deebot_client.models import State

from .common import JsonCommandWithMessageHandling
from .const import CODE

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus


class GetChargeState(JsonCommandWithMessageHandling, MessageBodyDataDict):
"""Get charge state command."""
Expand Down
12 changes: 8 additions & 4 deletions deebot_client/commands/json/clean.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""Clean commands."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.authentication import Authenticator
from deebot_client.command import CommandResult
from deebot_client.event_bus import EventBus
from deebot_client.events import StateEvent
from deebot_client.logging_filter import get_logger
from deebot_client.message import HandlingResult, MessageBodyDataDict
from deebot_client.models import CleanAction, CleanMode, DeviceInfo, State

from .common import ExecuteCommand, JsonCommandWithMessageHandling

if TYPE_CHECKING:
from deebot_client.authentication import Authenticator
from deebot_client.command import CommandResult
from deebot_client.event_bus import EventBus

_LOGGER = get_logger(__name__)


Expand Down
7 changes: 5 additions & 2 deletions deebot_client/commands/json/clean_count.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
"""Clean count command module."""
from __future__ import annotations

from types import MappingProxyType
from typing import Any
from typing import TYPE_CHECKING, Any

from deebot_client.command import InitParam
from deebot_client.event_bus import EventBus
from deebot_client.events import CleanCountEvent
from deebot_client.message import HandlingResult

from .common import JsonGetCommand, JsonSetCommand

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus


class GetCleanCount(JsonGetCommand):
"""Get clean count command."""
Expand Down
12 changes: 8 additions & 4 deletions deebot_client/commands/json/clean_logs.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
"""clean log commands."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.authentication import Authenticator
from deebot_client.command import CommandResult
from deebot_client.const import PATH_API_LG_LOG, REQUEST_HEADERS
from deebot_client.event_bus import EventBus
from deebot_client.events import CleanJobStatus, CleanLogEntry, CleanLogEvent
from deebot_client.logging_filter import get_logger
from deebot_client.models import DeviceInfo

from .common import JsonCommand

if TYPE_CHECKING:
from deebot_client.authentication import Authenticator
from deebot_client.event_bus import EventBus
from deebot_client.models import DeviceInfo

_LOGGER = get_logger(__name__)


Expand Down
1 change: 1 addition & 0 deletions deebot_client/commands/json/clean_preference.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Clean preference command module."""
from __future__ import annotations

from deebot_client.events import CleanPreferenceEvent

Expand Down
10 changes: 7 additions & 3 deletions deebot_client/commands/json/common.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Base commands."""
from __future__ import annotations

from abc import ABC, abstractmethod
from datetime import datetime
from types import MappingProxyType
from typing import Any
from typing import TYPE_CHECKING, Any

from deebot_client.command import (
Command,
Expand All @@ -12,8 +14,6 @@
SetCommand,
)
from deebot_client.const import DataType
from deebot_client.event_bus import EventBus
from deebot_client.events import EnableEvent
from deebot_client.logging_filter import get_logger
from deebot_client.message import (
HandlingResult,
Expand All @@ -24,6 +24,10 @@

from .const import CODE

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus
from deebot_client.events import EnableEvent

_LOGGER = get_logger(__name__)


Expand Down
1 change: 1 addition & 0 deletions deebot_client/commands/json/const.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Command constants module."""
from __future__ import annotations

CODE = "code"
1 change: 1 addition & 0 deletions deebot_client/commands/json/continuous_cleaning.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Continuous cleaning (break point) command module."""
from __future__ import annotations

from deebot_client.events import ContinuousCleaningEvent

Expand Down
8 changes: 6 additions & 2 deletions deebot_client/commands/json/custom.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Custom command module."""
from typing import Any
from __future__ import annotations

from typing import TYPE_CHECKING, Any

from deebot_client.command import CommandResult
from deebot_client.commands.json.common import JsonCommand
from deebot_client.event_bus import EventBus
from deebot_client.events import CustomCommandEvent
from deebot_client.logging_filter import get_logger
from deebot_client.message import HandlingState

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus

_LOGGER = get_logger(__name__)


Expand Down
Loading

0 comments on commit 95bb092

Please sign in to comment.