Skip to content

Commit

Permalink
go on
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus committed Dec 16, 2024
1 parent 1f6aa4f commit 8ef39ba
Show file tree
Hide file tree
Showing 14 changed files with 304 additions and 51 deletions.
45 changes: 30 additions & 15 deletions deebot_client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from dataclasses import dataclass, field, fields, is_dataclass
from enum import StrEnum
from types import MappingProxyType
from typing import TYPE_CHECKING, Any, Generic, TypeVar
from typing import TYPE_CHECKING, Any, Generic, ParamSpec, TypeVar

from deebot_client.events import (
AdvancedModeEvent,
Expand Down Expand Up @@ -67,6 +67,7 @@

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


def _get_events(
Expand Down Expand Up @@ -94,14 +95,14 @@ class CapabilityEvent(Generic[_EVENT]):


@dataclass(frozen=True)
class CapabilitySet(CapabilityEvent[_EVENT], Generic[_EVENT, _T]):
class CapabilitySet(CapabilityEvent[_EVENT], Generic[_EVENT, _P]):
"""Capability setCommand with event."""

set: Callable[[_T], ExecuteCommand]
set: Callable[_P, ExecuteCommand]


@dataclass(frozen=True)
class CapabilitySetEnable(CapabilitySet[_EVENT, bool]):
class CapabilitySetEnable(CapabilitySet[_EVENT, [bool]]):
"""Capability for SetEnableCommand with event."""


Expand All @@ -120,7 +121,7 @@ class CapabilityTypes(Generic[_T]):


@dataclass(frozen=True, kw_only=True)
class CapabilitySetTypes(CapabilitySet[_EVENT, _T | str], CapabilityTypes[_T]):
class CapabilitySetTypes(CapabilitySet[_EVENT, _P], CapabilityTypes[_T]):
"""Capability for set command and types."""


Expand All @@ -138,10 +139,12 @@ class CapabilityClean:

action: CapabilityCleanAction
continuous: CapabilitySetEnable[ContinuousCleaningEvent] | None = None
count: CapabilitySet[CleanCountEvent, int] | None = None
count: CapabilitySet[CleanCountEvent, [int]] | None = None
log: CapabilityEvent[CleanLogEvent] | None = None
preference: CapabilitySetEnable[CleanPreferenceEvent] | None = None
work_mode: CapabilitySetTypes[WorkModeEvent, WorkMode] | None = None
work_mode: CapabilitySetTypes[WorkModeEvent, [WorkMode | str], WorkMode] | None = (
None
)


@dataclass(frozen=True)
Expand Down Expand Up @@ -188,12 +191,13 @@ class CapabilitySettings:

advanced_mode: CapabilitySetEnable[AdvancedModeEvent] | None = None
carpet_auto_fan_boost: CapabilitySetEnable[CarpetAutoFanBoostEvent] | None = None
efficiency_mode: CapabilitySetTypes[EfficiencyModeEvent, EfficiencyMode] | None = (
None
)
efficiency_mode: (
CapabilitySetTypes[EfficiencyModeEvent, [EfficiencyMode | str], EfficiencyMode]
| None
) = None
border_switch: CapabilitySetEnable[BorderSwitchEvent] | None = None
child_lock: CapabilitySetEnable[ChildLockEvent] | None = None
cut_direction: CapabilitySet[CutDirectionEvent, int] | None = None
cut_direction: CapabilitySet[CutDirectionEvent, [int]] | None = None
moveup_warning: CapabilitySetEnable[MoveUpWarningEvent] | None = None
cross_map_border_warning: CapabilitySetEnable[CrossMapBorderWarningEvent] | None = (
None
Expand All @@ -203,14 +207,21 @@ class CapabilitySettings:
sweep_mode: CapabilitySetEnable[SweepModeEvent] | None = None
true_detect: CapabilitySetEnable[TrueDetectEvent] | None = None
voice_assistant: CapabilitySetEnable[VoiceAssistantStateEvent] | None = None
volume: CapabilitySet[VolumeEvent, int]
volume: CapabilitySet[VolumeEvent, [int]]


@dataclass(frozen=True, kw_only=True)
class CapabilityStation:
"""Capabilities for station."""

auto_empty: CapabilitySetTypes[auto_empty.Event, auto_empty.Frequency] | None = None
auto_empty: (
CapabilitySetTypes[
auto_empty.AutoEmptyEvent,
[bool | None, auto_empty.Frequency | str | None],
auto_empty.Frequency,
]
| None
) = None


@dataclass(frozen=True, kw_only=True)
Expand All @@ -225,7 +236,9 @@ class Capabilities(ABC):
clean: CapabilityClean
custom: CapabilityCustomCommand[CustomCommandEvent]
error: CapabilityEvent[ErrorEvent]
fan_speed: CapabilitySetTypes[FanSpeedEvent, FanSpeedLevel] | None = None
fan_speed: (
CapabilitySetTypes[FanSpeedEvent, [FanSpeedLevel | str], FanSpeedLevel] | None
) = None
life_span: CapabilityLifeSpan
map: CapabilityMap | None = None
network: CapabilityEvent[NetworkInfoEvent]
Expand All @@ -234,7 +247,9 @@ class Capabilities(ABC):
state: CapabilityEvent[StateEvent]
station: CapabilityStation = field(default_factory=CapabilityStation)
stats: CapabilityStats
water: CapabilitySetTypes[WaterInfoEvent, WaterAmount] | None = None
water: (
CapabilitySetTypes[WaterInfoEvent, [WaterAmount | str], WaterAmount] | None
) = None

_events: MappingProxyType[type[Event], list[Command]] = field(init=False)

Expand Down
6 changes: 3 additions & 3 deletions deebot_client/commands/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from deebot_client.command import Command, CommandMqttP2P

from . import auto_empty
from .advanced_mode import GetAdvancedMode, SetAdvancedMode
from .auto_empty import GetAutoEmpty, SetAutoEmpty
from .battery import GetBattery
from .border_switch import GetBorderSwitch, SetBorderSwitch
from .carpet import GetCarpetAutoFanBoost, SetCarpetAutoFanBoost
Expand Down Expand Up @@ -131,8 +131,8 @@
GetAdvancedMode,
SetAdvancedMode,

GetAutoEmpty,
SetAutoEmpty,
auto_empty.GetAutoEmpty,
auto_empty.SetAutoEmpty,

GetBorderSwitch,
SetBorderSwitch,
Expand Down
7 changes: 1 addition & 6 deletions deebot_client/commands/json/auto_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@

from .common import ExecuteCommand, JsonGetCommand

__all__ = [
"GetAutoEmpty",
"SetAutoEmpty",
]


class GetAutoEmpty(OnAutoEmpty, JsonGetCommand):
"""Get auto empty command."""
Expand All @@ -28,7 +23,7 @@ class SetAutoEmpty(ExecuteCommand):
name = "setAutoEmpty"

def __init__(
self, *, enable: bool | None = None, frequency: Frequency | str | None = None
self, enable: bool | None = None, frequency: Frequency | str | None = None
) -> None:
if frequency is not None and not isinstance(frequency, Frequency):
frequency = get_enum(Frequency, frequency)
Expand Down
2 changes: 1 addition & 1 deletion deebot_client/commands/json/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,5 @@ def __init_subclass__(cls, **kwargs: Any) -> None:
cls._mqtt_params = MappingProxyType({cls._field_name: InitParam(bool, _ENABLE)})
super().__init_subclass__(**kwargs)

def __init__(self, enable: bool) -> None: # noqa: FBT001
def __init__(self, enable: bool) -> None:
super().__init__({self._field_name: 1 if enable else 0})
2 changes: 1 addition & 1 deletion deebot_client/commands/json/ota.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ class SetOta(JsonSetCommand):

_mqtt_params = MappingProxyType({"autoSwitch": InitParam(bool, "auto_enabled")})

def __init__(self, auto_enabled: bool) -> None: # noqa: FBT001
def __init__(self, auto_enabled: bool) -> None:
super().__init__({"autoSwitch": 1 if auto_enabled else 0})
4 changes: 3 additions & 1 deletion deebot_client/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from deebot_client.events.base import Event

from . import auto_empty
from .auto_empty import AutoEmptyEvent
from .efficiency_mode import EfficiencyMode, EfficiencyModeEvent
from .fan_speed import FanSpeedEvent, FanSpeedLevel
from .map import (
Expand All @@ -32,7 +33,7 @@
from deebot_client.models import Room, State

__all__ = [
"auto_empty",
"AutoEmptyEvent",
"BatteryEvent",
"CachedMapInfoEvent",
"CleanJobStatus",
Expand All @@ -59,6 +60,7 @@
"WaterInfoEvent",
"WorkMode",
"WorkModeEvent",
"auto_empty",
]


Expand Down
4 changes: 2 additions & 2 deletions deebot_client/events/auto_empty.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .base import Event as _Event

__all__ = ["Event", "Frequency"]
__all__ = ["AutoEmptyEvent", "Frequency"]


@unique
Expand All @@ -22,7 +22,7 @@ class Frequency(StrEnum):


@dataclass(frozen=True)
class Event(_Event):
class AutoEmptyEvent(_Event):
"""Auto empty event representation."""

enabled: bool
Expand Down
2 changes: 1 addition & 1 deletion deebot_client/hardware/deebot/p95mgv.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@
state=CapabilityEvent(StateEvent, [GetChargeState(), GetCleanInfo()]),
station=CapabilityStation(
auto_empty=CapabilitySetTypes(
event=auto_empty.Event,
event=auto_empty.AutoEmptyEvent,
get=[GetAutoEmpty()],
set=SetAutoEmpty,
types=(
Expand Down
1 change: 0 additions & 1 deletion deebot_client/hardware/deebot/qhe2o2.py

This file was deleted.

Loading

0 comments on commit 8ef39ba

Please sign in to comment.