Skip to content

Commit 17dc2d1

Browse files
authored
Merge branch 'main' into supported_features_markdown
2 parents 7aa4c8f + 1addf95 commit 17dc2d1

29 files changed

+749
-292
lines changed

poetry.lock

Lines changed: 24 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "python-roborock"
3-
version = "2.33.0"
3+
version = "2.35.0"
44
description = "A package to control Roborock vacuums."
55
authors = ["humbertogontijo <humbertogontijo@users.noreply.github.com>"]
66
license = "GPL-3.0-only"

roborock/api.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
from __future__ import annotations
44

55
import asyncio
6-
import base64
76
import logging
8-
import secrets
97
import time
108
from abc import ABC, abstractmethod
119
from typing import Any
@@ -37,14 +35,11 @@ class RoborockClient(ABC):
3735
def __init__(self, device_info: DeviceData) -> None:
3836
"""Initialize RoborockClient."""
3937
self.device_info = device_info
40-
self._nonce = secrets.token_bytes(16)
4138
self._waiting_queue: dict[int, RoborockFuture] = {}
4239
self._last_device_msg_in = time.monotonic()
4340
self._last_disconnection = time.monotonic()
4441
self.keep_alive = KEEPALIVE
45-
self._diagnostic_data: dict[str, dict[str, Any]] = {
46-
"misc_info": {"Nonce": base64.b64encode(self._nonce).decode("utf-8")}
47-
}
42+
self._diagnostic_data: dict[str, dict[str, Any]] = {}
4843
self.is_available: bool = True
4944

5045
async def async_release(self) -> None:
@@ -116,7 +111,3 @@ def _async_response(self, request_id: int, protocol_id: int = 0) -> Any:
116111
request_id = new_id
117112
self._waiting_queue[request_id] = queue
118113
return asyncio.ensure_future(self._wait_response(request_id, queue))
119-
120-
@abstractmethod
121-
async def send_message(self, roborock_message: RoborockMessage):
122-
"""Send a message to the Roborock device."""

roborock/clean_modes.py

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
from __future__ import annotations
2+
3+
from enum import StrEnum
4+
5+
from roborock import DeviceFeatures
6+
7+
8+
class RoborockModeEnum(StrEnum):
9+
"""A custom StrEnum that also stores an integer code for each member."""
10+
11+
code: int
12+
13+
def __new__(cls, value: str, code: int) -> RoborockModeEnum:
14+
"""Creates a new enum member."""
15+
member = str.__new__(cls, value)
16+
member._value_ = value
17+
member.code = code
18+
return member
19+
20+
21+
class CleanModes(RoborockModeEnum):
22+
GENTLE = ("gentle", 105)
23+
OFF = ("off", 105)
24+
QUIET = ("quiet", 101)
25+
BALANCED = ("balanced", 102)
26+
TURBO = ("turbo", 103)
27+
MAX = ("max", 104)
28+
MAX_PLUS = ("max_plus", 108)
29+
CUSTOMIZED = ("custom", 106)
30+
SMART_MODE = ("smart_mode", 110)
31+
32+
33+
class CleanRoutes(RoborockModeEnum):
34+
STANDARD = ("standard", 300)
35+
DEEP = ("deep", 301)
36+
DEEP_PLUS = ("deep_plus", 303)
37+
FAST = ("fast", 304)
38+
DEEP_PLUS_CN = ("deep_plus", 305)
39+
SMART_MODE = ("smart_mode", 306)
40+
CUSTOMIZED = ("custom", 302)
41+
42+
43+
class CleanModesOld(RoborockModeEnum):
44+
QUIET = ("quiet", 38)
45+
BALANCED = ("balanced", 60)
46+
TURBO = ("turbo", 75)
47+
MAX = ("max", 100)
48+
49+
50+
class WaterModes(RoborockModeEnum):
51+
OFF = ("off", 200)
52+
LOW = ("low", 201)
53+
MILD = ("mild", 201)
54+
MEDIUM = ("medium", 202)
55+
STANDARD = ("standard", 202)
56+
HIGH = ("high", 203)
57+
INTENSE = ("intense", 203)
58+
CUSTOMIZED = ("custom", 204)
59+
CUSTOM = ("custom_water_flow", 207)
60+
EXTREME = ("extreme", 208)
61+
SMART_MODE = ("smart_mode", 209)
62+
63+
64+
def get_clean_modes(features: DeviceFeatures) -> list[CleanModes]:
65+
"""Get the valid clean modes for the device - also known as 'fan power' or 'suction mode'"""
66+
modes = [CleanModes.QUIET, CleanModes.BALANCED, CleanModes.TURBO, CleanModes.MAX]
67+
if features.is_max_plus_mode_supported or features.is_none_pure_clean_mop_with_max_plus:
68+
# If the vacuum has max plus mode supported
69+
modes.append(CleanModes.MAX_PLUS)
70+
if features.is_pure_clean_mop_supported:
71+
# If the vacuum is capable of 'pure mop clean' aka no vacuum
72+
modes.append(CleanModes.OFF)
73+
else:
74+
# If not, we can add gentle
75+
modes.append(CleanModes.GENTLE)
76+
return modes
77+
78+
79+
def get_clean_routes(features: DeviceFeatures, region: str) -> list[CleanRoutes]:
80+
"""The routes that the vacuum will take while mopping"""
81+
if features.is_none_pure_clean_mop_with_max_plus:
82+
return [CleanRoutes.FAST, CleanRoutes.STANDARD]
83+
supported = [CleanRoutes.STANDARD, CleanRoutes.DEEP]
84+
if features.is_careful_slow_mop_supported:
85+
if not (
86+
features.is_corner_clean_mode_supported
87+
and features.is_clean_route_deep_slow_plus_supported
88+
and region == "CN"
89+
):
90+
# for some reason there is a china specific deep plus mode
91+
supported.append(CleanRoutes.DEEP_PLUS_CN)
92+
else:
93+
supported.append(CleanRoutes.DEEP_PLUS)
94+
95+
if features.is_clean_route_fast_mode_supported:
96+
supported.append(CleanRoutes.FAST)
97+
return supported
98+
99+
100+
def get_water_modes(features: DeviceFeatures) -> list[WaterModes]:
101+
"""Get the valid water modes for the device - also known as 'water flow' or 'water level'"""
102+
supported_modes = [WaterModes.OFF]
103+
if features.is_mop_shake_module_supported:
104+
# For mops that have the vibrating mop pad, they do mild standard intense
105+
supported_modes.extend([WaterModes.MILD, WaterModes.STANDARD, WaterModes.INTENSE])
106+
else:
107+
supported_modes.extend([WaterModes.LOW, WaterModes.MEDIUM, WaterModes.HIGH])
108+
if features.is_custom_water_box_distance_supported:
109+
# This is for devices that allow you to set a custom water flow from 0-100
110+
supported_modes.append(WaterModes.CUSTOM)
111+
if features.is_mop_shake_module_supported and features.is_mop_shake_water_max_supported:
112+
supported_modes.append(WaterModes.EXTREME)
113+
return supported_modes

roborock/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ async def _discover(ctx):
164164
if not cache_data:
165165
raise Exception("You need to login first")
166166
client = RoborockApiClient(cache_data.email)
167-
home_data = await client.get_home_data(cache_data.user_data)
167+
home_data = await client.get_home_data_v3(cache_data.user_data)
168168
cache_data.home_data = home_data
169169
context.update(cache_data)
170170
click.echo(f"Discovered devices {', '.join([device.name for device in home_data.get_all_devices()])}")

roborock/containers.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,29 @@ class NetworkInfo(RoborockBase):
725725
rssi: int | None = None
726726

727727

728+
@dataclass
729+
class AppInitStatusLocalInfo(RoborockBase):
730+
location: str
731+
bom: str | None = None
732+
featureset: int | None = None
733+
language: str | None = None
734+
logserver: str | None = None
735+
wifiplan: str | None = None
736+
timezone: str | None = None
737+
name: str | None = None
738+
739+
740+
@dataclass
741+
class AppInitStatus(RoborockBase):
742+
local_info: AppInitStatusLocalInfo
743+
feature_info: list[int]
744+
new_feature_info: int
745+
new_feature_info_str: str
746+
new_feature_info_2: int | None = None
747+
carriage_type: int | None = None
748+
dsp_version: int | None = None
749+
750+
728751
@dataclass
729752
class DeviceData(RoborockBase):
730753
device: HomeDataDevice

roborock/device_features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ class DeviceFeatures:
423423
is_clean_route_setting_supported: bool = field(
424424
metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE, ProductFeatures.MOP_SPIN_MODULE]}
425425
)
426+
is_mop_shake_module_supported: bool = field(metadata={"product_features": [ProductFeatures.MOP_SHAKE_MODULE]})
426427

427428
@classmethod
428429
def from_feature_flags(

roborock/devices/b01_channel.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""Thin wrapper around the MQTT channel for Roborock B01 devices."""
2+
3+
from __future__ import annotations
4+
5+
import logging
6+
from typing import Any
7+
8+
from roborock.protocols.b01_protocol import (
9+
CommandType,
10+
ParamsType,
11+
decode_rpc_response,
12+
encode_mqtt_payload,
13+
)
14+
15+
from .mqtt_channel import MqttChannel
16+
17+
_LOGGER = logging.getLogger(__name__)
18+
19+
20+
async def send_decoded_command(
21+
mqtt_channel: MqttChannel,
22+
dps: int,
23+
command: CommandType,
24+
params: ParamsType,
25+
) -> dict[int, Any]:
26+
"""Send a command on the MQTT channel and get a decoded response."""
27+
_LOGGER.debug("Sending MQTT command: %s", params)
28+
roborock_message = encode_mqtt_payload(dps, command, params)
29+
response = await mqtt_channel.send_message(roborock_message)
30+
return decode_rpc_response(response) # type: ignore[return-value]

roborock/devices/device_manager.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from .cache import Cache, NoCache
2222
from .channel import Channel
2323
from .mqtt_channel import create_mqtt_channel
24+
from .traits.b01.props import B01PropsApi
2425
from .traits.dyad import DyadApi
2526
from .traits.status import StatusTrait
2627
from .traits.trait import Trait
@@ -45,6 +46,7 @@ class DeviceVersion(enum.StrEnum):
4546

4647
V1 = "1.0"
4748
A01 = "A01"
49+
B01 = "B01"
4850
UNKNOWN = "unknown"
4951

5052

@@ -120,7 +122,7 @@ def create_home_data_api(email: str, user_data: UserData) -> HomeDataApi:
120122
client = RoborockApiClient(email)
121123

122124
async def home_data_api() -> HomeData:
123-
return await client.get_home_data(user_data)
125+
return await client.get_home_data_v3(user_data)
124126

125127
return home_data_api
126128

@@ -159,6 +161,9 @@ def device_creator(device: HomeDataDevice, product: HomeDataProduct) -> Roborock
159161
traits.append(ZeoApi(mqtt_channel))
160162
case _:
161163
raise NotImplementedError(f"Device {device.name} has unsupported category {product.category}")
164+
case DeviceVersion.B01:
165+
mqtt_channel = create_mqtt_channel(user_data, mqtt_params, mqtt_session, device)
166+
traits.append(B01PropsApi(mqtt_channel))
162167
case _:
163168
raise NotImplementedError(f"Device {device.name} has unsupported version {device.pv}")
164169
return RoborockDevice(device, channel, traits)

roborock/devices/traits/b01/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)