Skip to content

Commit 2c21594

Browse files
committed
Add water capability
1 parent 65dd4d9 commit 2c21594

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

deebot_client/commands/xml/water_info.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22

33
from __future__ import annotations
44

5+
from types import MappingProxyType
56
from typing import TYPE_CHECKING, Any
67

8+
from deebot_client.command import InitParam
79
from deebot_client.events import (
810
WaterAmount,
911
WaterInfoEvent,
1012
)
1113
from deebot_client.message import HandlingResult
14+
from deebot_client.util import get_enum
1215

13-
from .common import XmlGetCommand
16+
from .common import XmlGetCommand, XmlSetCommand
1417

1518
if TYPE_CHECKING:
1619
from xml.etree.ElementTree import Element
@@ -47,6 +50,23 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
4750
return HandlingResult.success()
4851

4952

53+
class SetWaterPermeability(XmlSetCommand):
54+
"""SetWaterPermeability command."""
55+
56+
NAME = "SetWaterPermeability"
57+
get_command = GetWaterPermeability
58+
_mqtt_params = MappingProxyType(
59+
{
60+
"amount": InitParam(WaterAmount),
61+
}
62+
)
63+
64+
def __init__(self, amount: WaterAmount | str) -> None:
65+
if isinstance(amount, str):
66+
amount = get_enum(WaterAmount, amount)
67+
super().__init__({"v": str(amount.value)})
68+
69+
5070
class GetWaterBoxInfo(XmlGetCommand):
5171
"""GetWaterBoxInfo command."""
5272

@@ -60,11 +80,7 @@ def handle_set_args(
6080
6181
:return: A message response
6282
"""
63-
event_bus.notify(
64-
WaterInfoEvent(
65-
amount=WaterAmount.HIGH, mop_attached=(str(args["on"]) != "0")
66-
)
67-
)
83+
event_bus.notify(WaterInfoEvent(mop_attached=(str(args["on"]) != "0")))
6884
return HandlingResult.success()
6985

7086
@classmethod
@@ -76,7 +92,5 @@ def _handle_xml(cls, event_bus: EventBus, xml: Element) -> HandlingResult:
7692
if xml.attrib.get("ret") != "ok" or not (on := xml.attrib.get("on")):
7793
return HandlingResult.analyse()
7894

79-
event_bus.notify(
80-
WaterInfoEvent(amount=WaterAmount.HIGH, mop_attached=on != "0")
81-
)
95+
event_bus.notify(WaterInfoEvent(mop_attached=on != "0"))
8296
return HandlingResult.success()

deebot_client/events/water_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SweepType(IntEnum):
3030
class WaterInfoEvent(Event):
3131
"""Water info event representation."""
3232

33-
amount: WaterAmount
3433
# None means no data available
34+
amount: WaterAmount | None = None
3535
sweep_type: SweepType | None = None
3636
mop_attached: bool | None = field(kw_only=True, default=None)

deebot_client/hardware/deebot/2pv572.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@
2626
GetCleanSpeed,
2727
GetCleanState,
2828
GetLifeSpan,
29+
GetWaterPermeability,
2930
PlaySound,
3031
SetCleanSpeed,
3132
)
3233
from deebot_client.commands.xml.charge_state import GetChargeState
3334
from deebot_client.commands.xml.error import GetError
3435
from deebot_client.commands.xml.stats import GetCleanSum
36+
from deebot_client.commands.xml.water_info import GetWaterBoxInfo, SetWaterPermeability
3537
from deebot_client.const import DataType
3638
from deebot_client.events import (
3739
AvailabilityEvent,
@@ -48,6 +50,8 @@
4850
StateEvent,
4951
StatsEvent,
5052
TotalStatsEvent,
53+
WaterAmount,
54+
WaterInfoEvent,
5155
)
5256
from deebot_client.models import StaticDeviceInfo
5357
from deebot_client.util import short_name
@@ -97,5 +101,15 @@
97101
total=CapabilityEvent(TotalStatsEvent, [GetCleanSum()]),
98102
),
99103
settings=CapabilitySettings(),
104+
water=CapabilitySetTypes(
105+
event=WaterInfoEvent,
106+
get=[GetWaterPermeability(), GetWaterBoxInfo()],
107+
set=SetWaterPermeability,
108+
types=(
109+
WaterAmount.LOW,
110+
WaterAmount.MEDIUM,
111+
WaterAmount.HIGH,
112+
),
113+
),
100114
),
101115
)

0 commit comments

Comments
 (0)