Skip to content

Commit 0ed4902

Browse files
committed
feat: add more data and region
1 parent 647073f commit 0ed4902

File tree

8 files changed

+30
-10
lines changed

8 files changed

+30
-10
lines changed

roborock/data/v1/v1_clean_modes.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class VacuumModes(RoborockModeEnum):
1616
TURBO = ("turbo", 103)
1717
MAX = ("max", 104)
1818
MAX_PLUS = ("max_plus", 108)
19+
CARPET = ("carpet", 107)
20+
OFF_RAISE_MAIN_BRUSH = ("off", 109)
1921
CUSTOMIZED = ("custom", 106)
2022
SMART_MODE = ("smart_mode", 110)
2123

@@ -45,6 +47,8 @@ class WaterModes(RoborockModeEnum):
4547
STANDARD = ("standard", 202)
4648
HIGH = ("high", 203)
4749
INTENSE = ("intense", 203)
50+
MIN = ("min", 205)
51+
MAX = ("max", 206)
4852
CUSTOMIZED = ("custom", 204)
4953
CUSTOM = ("custom_water_flow", 207)
5054
EXTREME = ("extreme", 208)
@@ -81,9 +85,14 @@ def get_clean_modes(features: DeviceFeatures) -> list[VacuumModes]:
8185
if features.is_max_plus_mode_supported or features.is_none_pure_clean_mop_with_max_plus:
8286
# If the vacuum has max plus mode supported
8387
modes.append(VacuumModes.MAX_PLUS)
88+
if features.is_carpet_deep_clean_supported:
89+
modes.append(VacuumModes.CARPET)
8490
if features.is_pure_clean_mop_supported:
8591
# If the vacuum is capable of 'pure mop clean' aka no vacuum
86-
modes.append(VacuumModes.OFF)
92+
if features.is_support_main_brush_up_down_supported:
93+
modes.append(VacuumModes.OFF_RAISE_MAIN_BRUSH)
94+
else:
95+
modes.append(VacuumModes.OFF)
8796
else:
8897
# If not, we can add gentle
8998
modes.append(VacuumModes.GENTLE)

roborock/data/v1/v1_containers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def __repr__(self) -> str:
256256
return _attr_repr(self)
257257

258258

259+
@dataclass
259260
class StatusV2(RoborockBase):
260261
"""
261262
This is a new version of the Status object.

roborock/devices/device_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def device_creator(home_data: HomeData, device: HomeDataDevice, product: HomeDat
215215
web_api,
216216
device_cache=device_cache,
217217
map_parser_config=map_parser_config,
218+
region=user_data.region,
218219
)
219220
case DeviceVersion.A01:
220221
channel = create_mqtt_channel(user_data, mqtt_params, mqtt_session, device)

roborock/devices/traits/v1/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848

4949
import logging
5050
from dataclasses import dataclass, field, fields
51-
from functools import cache
5251
from typing import Any, get_args
5352

5453
from roborock.data.containers import HomeData, HomeDataProduct, RoborockBase
@@ -174,24 +173,24 @@ def __init__(
174173
web_api: UserWebApiClient,
175174
device_cache: DeviceCache,
176175
map_parser_config: MapParserConfig | None = None,
176+
region: str | None = None,
177177
) -> None:
178178
"""Initialize the V1TraitProps."""
179179
self._device_uid = device_uid
180180
self._rpc_channel = rpc_channel
181181
self._mqtt_rpc_channel = mqtt_rpc_channel
182182
self._map_rpc_channel = map_rpc_channel
183183
self._web_api = web_api
184-
self._cache = cache
185-
self.device_features = DeviceFeaturesTrait(product.product_nickname, cache)
186184
self._device_cache = device_cache
185+
self._region = region
187186

188-
self.status = StatusTrait(self.device_features)
187+
self.device_features = DeviceFeaturesTrait(product.product_nickname, self._device_cache)
188+
self.status = StatusTrait(self.device_features, region=self._region)
189189
self.consumables = ConsumableTrait()
190190
self.rooms = RoomsTrait(home_data)
191191
self.maps = MapsTrait(self.status)
192192
self.map_content = MapContentTrait(map_parser_config)
193193
self.home = HomeTrait(self.status, self.maps, self.map_content, self.rooms, self._device_cache)
194-
self.device_features = DeviceFeaturesTrait(product.product_nickname, self._device_cache)
195194
self.network_info = NetworkInfoTrait(device_uid, self._device_cache)
196195
self.routines = RoutinesTrait(device_uid, web_api)
197196

@@ -202,6 +201,8 @@ def __init__(
202201
if (union_args := get_args(item.type)) is None or len(union_args) > 0:
203202
continue
204203
_LOGGER.debug("Trait '%s' is supported, initializing", item.name)
204+
if not callable(item.type):
205+
continue
205206
trait = item.type()
206207
setattr(self, item.name, trait)
207208
# This is a hack to allow setting the rpc_channel on all traits. This is
@@ -320,6 +321,7 @@ def create(
320321
web_api: UserWebApiClient,
321322
device_cache: DeviceCache,
322323
map_parser_config: MapParserConfig | None = None,
324+
region: str | None = None,
323325
) -> PropertiesApi:
324326
"""Create traits for V1 devices."""
325327
return PropertiesApi(
@@ -332,4 +334,5 @@ def create(
332334
web_api,
333335
device_cache,
334336
map_parser_config,
337+
region=region,
335338
)

roborock/devices/traits/v1/status.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
from typing import Self
33

44
from roborock import CleanRoutes, StatusV2, VacuumModes, WaterModes, get_clean_modes, get_clean_routes, get_water_modes
5-
from roborock.devices.traits.v1 import DeviceFeaturesTrait, common
65
from roborock.roborock_typing import RoborockCommand
76

7+
from . import common
8+
from .device_features import DeviceFeaturesTrait
9+
810

911
class StatusTrait(StatusV2, common.V1TraitMixin):
1012
"""Trait for managing the status of Roborock devices."""
1113

1214
command = RoborockCommand.GET_STATUS
1315

14-
def __init__(self, device_feature_trait: DeviceFeaturesTrait) -> None:
16+
def __init__(self, device_feature_trait: DeviceFeaturesTrait, region: str | None = None) -> None:
1517
"""Initialize the StatusTrait."""
18+
super().__init__()
1619
self._device_features_trait = device_feature_trait
20+
self._region = region
1721

1822
@cached_property
1923
def fan_speed_options(self) -> list[VacuumModes]:
@@ -33,7 +37,7 @@ def water_mode_mapping(self) -> dict[int, str]:
3337

3438
@cached_property
3539
def mop_route_options(self) -> list[CleanRoutes]:
36-
return get_clean_routes(self._device_features_trait, "US") # TODO: find best place to get region
40+
return get_clean_routes(self._device_features_trait, self._region or "us")
3741

3842
@cached_property
3943
def mop_route_mapping(self) -> dict[int, str]:

tests/devices/__snapshots__/test_v1_device.ambr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@
832832
})
833833
# ---
834834
# name: test_device_trait_command_parsing[status]
835-
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, corner_clean_mode=None, current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=<RoborockFanSpeedS7MaxV.custom: 106>, fan_power_name='custom', fan_power_options=['off', 'quiet', 'balanced', 'turbo', 'max', 'custom', 'max_plus'], hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_exploring=None, is_locating=0, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_mode_name=None, msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=<RoborockMopIntensityS7.custom: 204>, water_box_mode_name='custom', water_box_status=0, water_shortage_status=None)
835+
StatusTrait(adbumper_status=None, auto_dust_collection=None, avoid_count=None, back_type=None, battery=100, camera_status=None, charge_status=None, clean_area=91287500, clean_fluid_status=None, clean_percent=None, clean_time=5405, clear_water_box_status=None, collision_avoid_status=None, command=<RoborockCommand.GET_STATUS: 'get_status'>, common_status=None, corner_clean_mode=None, current_map=0, debug_mode=None, dirty_water_box_status=None, distance_off=0, dnd_enabled=1, dock_cool_fan_status=None, dock_error_status=None, dock_type=None, dry_status=None, dss=None, dust_bag_status=None, dust_collection_status=None, error_code=<RoborockErrorCode.none: 0>, error_code_name='none', fan_power=106, fan_speed_mapping={101: 'QUIET', 102: 'BALANCED', 103: 'TURBO', 104: 'MAX', 105: 'GENTLE'}, fan_speed_name=None, fan_speed_options=[<VacuumModes.QUIET: 'quiet'>, <VacuumModes.BALANCED: 'balanced'>, <VacuumModes.TURBO: 'turbo'>, <VacuumModes.MAX: 'max'>, <VacuumModes.GENTLE: 'gentle'>], hatch_door_status=None, home_sec_enable_password=None, home_sec_status=None, in_cleaning=<RoborockInCleaning.complete: 0>, in_fresh_state=1, in_returning=0, in_warmup=None, is_exploring=None, is_locating=0, kct=None, lab_status=1, last_clean_t=None, lock_status=0, map_present=1, map_status=3, mop_forbidden_enable=0, mop_mode=None, mop_route_mapping={300: 'STANDARD', 301: 'DEEP'}, mop_route_name=None, mop_route_options=[<CleanRoutes.STANDARD: 'standard'>, <CleanRoutes.DEEP: 'deep'>], msg_seq=515, msg_ver=2, rdt=None, repeat=None, replenish_mode=None, rss=None, square_meter_clean_area=91.3, state=<RoborockStateCode.charging: 8>, state_name='charging', subdivision_sets=None, switch_map_mode=None, unsave_map_flag=0, unsave_map_reason=4, wash_phase=None, wash_ready=None, wash_status=None, water_box_carriage_status=0, water_box_filter_status=None, water_box_mode=204, water_box_status=0, water_mode_mapping={200: 'OFF', 201: 'LOW', 202: 'MEDIUM', 203: 'HIGH'}, water_mode_name=None, water_mode_options=[<WaterModes.OFF: 'off'>, <WaterModes.LOW: 'low'>, <WaterModes.MEDIUM: 'medium'>, <WaterModes.HIGH: 'high'>], water_shortage_status=None)
836836
# ---
837837
# name: test_device_trait_command_parsing[status].1
838838
dict({

tests/devices/test_v1_device.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def device_fixture(channel: AsyncMock, rpc_channel: AsyncMock, mqtt_rpc_channel:
6565
AsyncMock(),
6666
AsyncMock(),
6767
device_cache=DeviceCache(HOME_DATA.devices[0].duid, NoCache()),
68+
region=USER_DATA.region,
6869
),
6970
)
7071

tests/devices/traits/v1/fixtures.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def device_fixture(
8181
mock_map_rpc_channel,
8282
web_api_client,
8383
device_cache=device_cache,
84+
region=USER_DATA.region,
8485
),
8586
)
8687

0 commit comments

Comments
 (0)