Skip to content

Commit

Permalink
Merge branch 'dev' into feature/align_viewbox_to_map
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored May 29, 2024
2 parents 4ce9449 + d12ef19 commit de7a37e
Show file tree
Hide file tree
Showing 23 changed files with 434 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ default_language_version:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.3
rev: v0.4.4
hooks:
- id: ruff
args:
Expand Down
2 changes: 2 additions & 0 deletions deebot_client/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ContinuousCleaningEvent,
CrossMapBorderWarningEvent,
CustomCommandEvent,
CutDirectionEvent,
ErrorEvent,
Event,
FanSpeedEvent,
Expand Down Expand Up @@ -189,6 +190,7 @@ class CapabilitySettings:
)
border_switch: CapabilitySetEnable[BorderSwitchEvent] | None = None
child_lock: CapabilitySetEnable[ChildLockEvent] | None = None
cut_direction: CapabilitySet[CutDirectionEvent, int] | None = None
moveup_warning: CapabilitySetEnable[MoveUpWarningEvent] | None = None
cross_map_border_warning: CapabilitySetEnable[CrossMapBorderWarningEvent] | None = (
None
Expand Down
3 changes: 3 additions & 0 deletions deebot_client/commands/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from .clear_map import ClearMap
from .continuous_cleaning import GetContinuousCleaning, SetContinuousCleaning
from .cross_map_border_warning import GetCrossMapBorderWarning, SetCrossMapBorderWarning
from .cut_direction import GetCutDirection, SetCutDirection
from .efficiency import GetEfficiencyMode, SetEfficiencyMode
from .error import GetError
from .fan_speed import GetFanSpeed, SetFanSpeed
Expand Down Expand Up @@ -77,6 +78,8 @@
"GetCleanLogs",
"GetContinuousCleaning",
"SetContinuousCleaning",
"SetCutDirection",
"GetCutDirection",
"GetCrossMapBorderWarning",
"SetCrossMapBorderWarning",
"GetEfficiencyMode",
Expand Down
43 changes: 43 additions & 0 deletions deebot_client/commands/json/cut_direction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Cut direction command module."""

from __future__ import annotations

from types import MappingProxyType
from typing import TYPE_CHECKING, Any

from deebot_client.command import InitParam
from deebot_client.events import CutDirectionEvent
from deebot_client.message import HandlingResult

from .common import JsonGetCommand, JsonSetCommand

if TYPE_CHECKING:
from deebot_client.event_bus import EventBus


class GetCutDirection(JsonGetCommand):
"""Get cut direction command."""

name = "getCutDirection"

@classmethod
def _handle_body_data_dict(
cls, event_bus: EventBus, data: dict[str, Any]
) -> HandlingResult:
"""Handle message->body->data and notify the correct event subscribers.
:return: A message response
"""
event_bus.notify(CutDirectionEvent(angle=data["angle"]))
return HandlingResult.success()


class SetCutDirection(JsonSetCommand):
"""Set cut direction command."""

name = "setCutDirection"
get_command = GetCutDirection
_mqtt_params = MappingProxyType({"angle": InitParam(int)})

def __init__(self, angle: int) -> None:
super().__init__({"angle": angle})
19 changes: 12 additions & 7 deletions deebot_client/commands/json/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ def _handle_body_data_dict(
:return: A message response
"""
codes = data.get("code", [])
codes = data.get("code")
if not isinstance(codes, list):
return HandlingResult.analyse()

error: int | None = 0

if codes:
# the last error code
error = codes[-1]

if error is not None:
description = ERROR_CODES.get(error)
if error != 0:
event_bus.notify(StateEvent(State.ERROR))
event_bus.notify(ErrorEvent(error, description))
return HandlingResult.success()
if error is not None:
description = ERROR_CODES.get(error)
if error != 0:
event_bus.notify(StateEvent(State.ERROR))
event_bus.notify(ErrorEvent(error, description))
return HandlingResult.success()

return HandlingResult.analyse()
6 changes: 5 additions & 1 deletion deebot_client/commands/json/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ def _handle_body_data_dict(
type=PositionType(type_str),
x=data_positions["x"],
y=data_positions["y"],
a=data_positions.get("a", 0),
)
)
else:
positions.extend(
[
Position(
type=PositionType(type_str), x=entry["x"], y=entry["y"]
type=PositionType(type_str),
x=entry["x"],
y=entry["y"],
a=entry.get("a", 0),
)
for entry in data_positions
]
Expand Down
5 changes: 4 additions & 1 deletion deebot_client/commands/xml/pos.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:

if p := xml.attrib.get("p"):
p_x, p_y = p.split(",", 2)
position = Position(type=PositionType.DEEBOT, x=int(p_x), y=int(p_y))
p_a = xml.attrib.get("a", 0)
position = Position(
type=PositionType.DEEBOT, x=int(p_x), y=int(p_y), a=int(p_a)
)
event_bus.notify(PositionsEvent(positions=[position]))
return HandlingResult.success()

Expand Down
11 changes: 11 additions & 0 deletions deebot_client/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ class LifeSpan(str, Enum):
HUMIDIFY_MAINTENANCE = "wbCare"
BLADE = "blade"
LENS_BRUSH = "lensBrush"
DUST_BAG = "dustBag"
CLEANING_FLUID = "autoWater_cleaningFluid"
STRAINER = "strainer"
HAND_FILTER = "handFilter"


@dataclass(frozen=True)
Expand Down Expand Up @@ -283,3 +287,10 @@ class MoveUpWarningEvent(EnableEvent):
@dataclass(frozen=True)
class SafeProtectEvent(EnableEvent):
"""Safe protect event."""


@dataclass(frozen=True)
class CutDirectionEvent(Event):
"""Cut direction event representation."""

angle: int
1 change: 1 addition & 0 deletions deebot_client/events/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Position:
type: PositionType
x: int
y: int
a: int


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions deebot_client/hardware/deebot/2ap5uq.py
6 changes: 6 additions & 0 deletions deebot_client/hardware/deebot/5xu9h3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
GetBorderSwitch,
GetChildLock,
GetCrossMapBorderWarning,
GetCutDirection,
GetMoveUpWarning,
GetSafeProtect,
SetBorderSwitch,
SetChildLock,
SetCrossMapBorderWarning,
SetCutDirection,
SetMoveUpWarning,
SetSafeProtect,
)
Expand All @@ -49,6 +51,7 @@
ChildLockEvent,
CrossMapBorderWarningEvent,
CustomCommandEvent,
CutDirectionEvent,
ErrorEvent,
LifeSpan,
LifeSpanEvent,
Expand Down Expand Up @@ -104,6 +107,9 @@
border_switch=CapabilitySetEnable(
BorderSwitchEvent, [GetBorderSwitch()], SetBorderSwitch
),
cut_direction=CapabilitySet(
CutDirectionEvent, [GetCutDirection()], SetCutDirection
),
child_lock=CapabilitySetEnable(
ChildLockEvent, [GetChildLock()], SetChildLock
),
Expand Down
Loading

0 comments on commit de7a37e

Please sign in to comment.