Skip to content

Commit

Permalink
Refactor station action (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Dec 23, 2024
1 parent 53f3f6e commit c34162e
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 59 deletions.
25 changes: 15 additions & 10 deletions deebot_client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from deebot_client.events import (
AdvancedModeEvent,
AvailabilityEvent,
BaseStationEvent,
BatteryEvent,
BorderSwitchEvent,
CachedMapInfoEvent,
Expand Down Expand Up @@ -42,6 +41,7 @@
RoomsEvent,
SafeProtectEvent,
StateEvent,
StationEvent,
StatsEvent,
SweepModeEvent,
TotalStatsEvent,
Expand All @@ -61,7 +61,7 @@
from _typeshed import DataclassInstance

from deebot_client.command import Command
from deebot_client.commands import BaseStationAction
from deebot_client.commands import StationAction
from deebot_client.commands.json.common import ExecuteCommand
from deebot_client.events.efficiency_mode import EfficiencyMode, EfficiencyModeEvent
from deebot_client.models import CleanAction, CleanMode
Expand Down Expand Up @@ -109,10 +109,10 @@ class CapabilitySetEnable(CapabilitySet[_EVENT, [bool]]):


@dataclass(frozen=True)
class CapabilityExecute:
class CapabilityExecute(Generic[_P]):
"""Capability to execute a command."""

execute: type[Command]
execute: Callable[_P, Command]


@dataclass(frozen=True, kw_only=True)
Expand All @@ -122,6 +122,11 @@ class CapabilityTypes(Generic[_T]):
types: tuple[_T, ...]


@dataclass(frozen=True, kw_only=True)
class CapabilityExecuteTypes(CapabilityTypes[_T], CapabilityExecute[[_T]]):
"""Capability to execute a command with types."""


@dataclass(frozen=True, kw_only=True)
class CapabilitySetTypes(CapabilitySet[_EVENT, _P], CapabilityTypes[_T]):
"""Capability for set command and types."""
Expand Down Expand Up @@ -169,11 +174,11 @@ class CapabilityMap:

cached_info: CapabilityEvent[CachedMapInfoEvent]
changed: CapabilityEvent[MapChangedEvent]
clear: CapabilityExecute | None = None
clear: CapabilityExecute[[]] | None = None
major: CapabilityEvent[MajorMapEvent]
multi_state: CapabilitySetEnable[MultimapStateEvent]
position: CapabilityEvent[PositionsEvent]
relocation: CapabilityExecute
relocation: CapabilityExecute[[]]
rooms: CapabilityEvent[RoomsEvent]
trace: CapabilityEvent[MapTraceEvent]

Expand Down Expand Up @@ -216,13 +221,13 @@ class CapabilitySettings:
class CapabilityBaseStation:
"""Capabilities for the base station."""

action: Callable[[BaseStationAction], Command]
action: CapabilityExecuteTypes[StationAction]
auto_empty: CapabilitySetTypes[
auto_empty.AutoEmptyEvent,
[bool | None, auto_empty.Frequency | str | None],
auto_empty.Frequency,
]
status: CapabilityEvent[BaseStationEvent]
state: CapabilityEvent[StationEvent]


@dataclass(frozen=True, kw_only=True)
Expand All @@ -234,7 +239,7 @@ class Capabilities(ABC):
availability: CapabilityEvent[AvailabilityEvent]
base_station: CapabilityBaseStation | None = None
battery: CapabilityEvent[BatteryEvent]
charge: CapabilityExecute
charge: CapabilityExecute[[]]
clean: CapabilityClean
custom: CapabilityCustomCommand[CustomCommandEvent]
error: CapabilityEvent[ErrorEvent]
Expand All @@ -244,7 +249,7 @@ class Capabilities(ABC):
life_span: CapabilityLifeSpan
map: CapabilityMap | None = None
network: CapabilityEvent[NetworkInfoEvent]
play_sound: CapabilityExecute
play_sound: CapabilityExecute[[]]
settings: CapabilitySettings
state: CapabilityEvent[StateEvent]
stats: CapabilityStats
Expand Down
4 changes: 2 additions & 2 deletions deebot_client/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


@unique
class BaseStationAction(IntEnum):
"""Enum class for all possible base station actions."""
class StationAction(IntEnum):
"""Enum class for all possible station actions."""

EMPTY_DUSTBIN = 1
8 changes: 2 additions & 6 deletions deebot_client/commands/json/station_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,16 @@

from typing import TYPE_CHECKING

from deebot_client.logging_filter import get_logger

from .common import ExecuteCommand

if TYPE_CHECKING:
from deebot_client.commands import BaseStationAction

_LOGGER = get_logger(__name__)
from deebot_client import commands


class StationAction(ExecuteCommand):
"""Station Action command."""

NAME = "stationAction"

def __init__(self, action: BaseStationAction) -> None:
def __init__(self, action: commands.StationAction) -> None:
super().__init__({"act": 1, "type": action.value})
8 changes: 4 additions & 4 deletions deebot_client/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@

from deebot_client.events.base import Event

from . import auto_empty, base_station
from . import auto_empty, station
from .auto_empty import AutoEmptyEvent
from .base_station import BaseStationEvent
from .efficiency_mode import EfficiencyMode, EfficiencyModeEvent
from .fan_speed import FanSpeedEvent, FanSpeedLevel
from .map import (
Expand All @@ -27,6 +26,7 @@
PositionType,
)
from .network import NetworkInfoEvent
from .station import StationEvent
from .water_info import SweepType, WaterAmount, WaterInfoEvent
from .work_mode import WorkMode, WorkModeEvent

Expand All @@ -35,7 +35,6 @@

__all__ = [
"AutoEmptyEvent",
"BaseStationEvent",
"BatteryEvent",
"CachedMapInfoEvent",
"CleanJobStatus",
Expand All @@ -56,14 +55,15 @@
"Position",
"PositionType",
"PositionsEvent",
"StationEvent",
"SweepModeEvent",
"SweepType",
"WaterAmount",
"WaterInfoEvent",
"WorkMode",
"WorkModeEvent",
"auto_empty",
"base_station",
"station",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

from .base import Event as _Event

__all__ = ["BaseStationEvent", "Status"]
__all__ = ["State", "StationEvent"]


@unique
class Status(IntEnum):
class State(IntEnum):
"""Enum class for all possible base station statuses."""

IDLE = 0
EMPTYING = 1


@dataclass(frozen=True)
class BaseStationEvent(_Event):
class StationEvent(_Event):
"""Base Station Event representation."""

state: Status
state: State
12 changes: 8 additions & 4 deletions deebot_client/hardware/deebot/buom7k.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CapabilityCustomCommand,
CapabilityEvent,
CapabilityExecute,
CapabilityExecuteTypes,
CapabilityLifeSpan,
CapabilityMap,
CapabilitySet,
Expand All @@ -19,6 +20,8 @@
CapabilityStats,
DeviceType,
)
from deebot_client.commands import StationAction
from deebot_client.commands.json import station_action
from deebot_client.commands.json.auto_empty import GetAutoEmpty, SetAutoEmpty
from deebot_client.commands.json.battery import GetBattery
from deebot_client.commands.json.carpet import (
Expand Down Expand Up @@ -48,15 +51,13 @@
from deebot_client.commands.json.play_sound import PlaySound
from deebot_client.commands.json.pos import GetPos
from deebot_client.commands.json.relocation import SetRelocationState
from deebot_client.commands.json.station_action import StationAction
from deebot_client.commands.json.station_state import GetStationState
from deebot_client.commands.json.stats import GetStats, GetTotalStats
from deebot_client.commands.json.volume import GetVolume, SetVolume
from deebot_client.commands.json.water_info import GetWaterInfo, SetWaterInfo
from deebot_client.const import DataType
from deebot_client.events import (
AvailabilityEvent,
BaseStationEvent,
BatteryEvent,
CachedMapInfoEvent,
CarpetAutoFanBoostEvent,
Expand All @@ -79,6 +80,7 @@
ReportStatsEvent,
RoomsEvent,
StateEvent,
StationEvent,
StatsEvent,
TotalStatsEvent,
VolumeEvent,
Expand All @@ -100,7 +102,9 @@
AvailabilityEvent, [GetBattery(is_available_check=True)]
),
base_station=CapabilityBaseStation(
action=StationAction,
action=CapabilityExecuteTypes(
station_action.StationAction, types=(StationAction.EMPTY_DUSTBIN,)
),
auto_empty=CapabilitySetTypes(
event=AutoEmptyEvent,
get=[GetAutoEmpty()],
Expand All @@ -110,7 +114,7 @@
auto_empty.Frequency.SMART,
),
),
status=CapabilityEvent(BaseStationEvent, [GetStationState()]),
state=CapabilityEvent(StationEvent, [GetStationState()]),
),
battery=CapabilityEvent(BatteryEvent, [GetBattery()]),
charge=CapabilityExecute(Charge),
Expand Down
12 changes: 8 additions & 4 deletions deebot_client/hardware/deebot/p95mgv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CapabilityCustomCommand,
CapabilityEvent,
CapabilityExecute,
CapabilityExecuteTypes,
CapabilityLifeSpan,
CapabilityMap,
CapabilitySet,
Expand All @@ -19,6 +20,8 @@
CapabilityStats,
DeviceType,
)
from deebot_client.commands import StationAction
from deebot_client.commands.json import station_action
from deebot_client.commands.json.advanced_mode import GetAdvancedMode, SetAdvancedMode
from deebot_client.commands.json.auto_empty import GetAutoEmpty, SetAutoEmpty
from deebot_client.commands.json.battery import GetBattery
Expand Down Expand Up @@ -57,7 +60,6 @@
from deebot_client.commands.json.play_sound import PlaySound
from deebot_client.commands.json.pos import GetPos
from deebot_client.commands.json.relocation import SetRelocationState
from deebot_client.commands.json.station_action import StationAction
from deebot_client.commands.json.station_state import GetStationState
from deebot_client.commands.json.stats import GetStats, GetTotalStats
from deebot_client.commands.json.true_detect import GetTrueDetect, SetTrueDetect
Expand All @@ -71,7 +73,6 @@
from deebot_client.events import (
AdvancedModeEvent,
AvailabilityEvent,
BaseStationEvent,
BatteryEvent,
CachedMapInfoEvent,
CarpetAutoFanBoostEvent,
Expand All @@ -95,6 +96,7 @@
ReportStatsEvent,
RoomsEvent,
StateEvent,
StationEvent,
StatsEvent,
TotalStatsEvent,
TrueDetectEvent,
Expand All @@ -118,7 +120,9 @@
AvailabilityEvent, [GetBattery(is_available_check=True)]
),
base_station=CapabilityBaseStation(
action=StationAction,
action=CapabilityExecuteTypes(
station_action.StationAction, types=(StationAction.EMPTY_DUSTBIN,)
),
auto_empty=CapabilitySetTypes(
event=auto_empty.AutoEmptyEvent,
get=[GetAutoEmpty()],
Expand All @@ -130,7 +134,7 @@
auto_empty.Frequency.AUTO,
),
),
status=CapabilityEvent(BaseStationEvent, [GetStationState()]),
state=CapabilityEvent(StationEvent, [GetStationState()]),
),
battery=CapabilityEvent(BatteryEvent, [GetBattery()]),
charge=CapabilityExecute(Charge),
Expand Down
12 changes: 8 additions & 4 deletions deebot_client/hardware/deebot/qhe2o2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
CapabilityCustomCommand,
CapabilityEvent,
CapabilityExecute,
CapabilityExecuteTypes,
CapabilityLifeSpan,
CapabilityMap,
CapabilitySet,
Expand All @@ -19,6 +20,8 @@
CapabilityStats,
DeviceType,
)
from deebot_client.commands import StationAction
from deebot_client.commands.json import station_action
from deebot_client.commands.json.auto_empty import GetAutoEmpty, SetAutoEmpty
from deebot_client.commands.json.battery import GetBattery
from deebot_client.commands.json.carpet import (
Expand Down Expand Up @@ -48,7 +51,6 @@
from deebot_client.commands.json.play_sound import PlaySound
from deebot_client.commands.json.pos import GetPos
from deebot_client.commands.json.relocation import SetRelocationState
from deebot_client.commands.json.station_action import StationAction
from deebot_client.commands.json.station_state import GetStationState
from deebot_client.commands.json.stats import GetStats, GetTotalStats
from deebot_client.commands.json.volume import GetVolume, SetVolume
Expand All @@ -57,7 +59,6 @@
from deebot_client.events import (
AutoEmptyEvent,
AvailabilityEvent,
BaseStationEvent,
BatteryEvent,
CachedMapInfoEvent,
CarpetAutoFanBoostEvent,
Expand All @@ -80,6 +81,7 @@
ReportStatsEvent,
RoomsEvent,
StateEvent,
StationEvent,
StatsEvent,
TotalStatsEvent,
VolumeEvent,
Expand All @@ -101,7 +103,9 @@
),
battery=CapabilityEvent(BatteryEvent, [GetBattery()]),
base_station=CapabilityBaseStation(
action=StationAction,
action=CapabilityExecuteTypes(
station_action.StationAction, types=(StationAction.EMPTY_DUSTBIN,)
),
auto_empty=CapabilitySetTypes(
event=AutoEmptyEvent,
get=[GetAutoEmpty()],
Expand All @@ -111,7 +115,7 @@
auto_empty.Frequency.SMART,
),
),
status=CapabilityEvent(BaseStationEvent, [GetStationState()]),
state=CapabilityEvent(StationEvent, [GetStationState()]),
),
charge=CapabilityExecute(Charge),
clean=CapabilityClean(
Expand Down
Loading

0 comments on commit c34162e

Please sign in to comment.