Skip to content

Commit a6f30b6

Browse files
committed
feat: expose in_cleaning, in_returning, charge_status, and dss on V1VacuumSimulator
1 parent 2054001 commit a6f30b6

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

roborock/testing/v1_simulator.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def __init__(
9393
custom_handlers: dict[str, Callable[[list[Any]], Any]] | None = None,
9494
device_info: HomeDataDevice | None = None,
9595
product: HomeDataProduct | None = None,
96+
dss: int = 169,
9697
):
9798
super().__init__(duid=duid, device_info=device_info, product=product)
9899
self.battery = battery
@@ -102,6 +103,7 @@ def __init__(
102103
self.mop_mode = mop_mode
103104
self.water_box_mode = water_box_mode
104105
self.custom_handlers = custom_handlers or {}
106+
self.dss = dss
105107

106108
self.consumables = {
107109
"main_brush_work_time": 74382,
@@ -181,6 +183,21 @@ def v1_channel(self) -> V1Channel:
181183
"""Returns the real V1Channel bound to the fake channels."""
182184
return self._v1_channel
183185

186+
@property
187+
def in_cleaning(self) -> int:
188+
"""Return 1 if cleaning, else 0."""
189+
return 1 if self.state == RoborockStateCode.cleaning else 0
190+
191+
@property
192+
def in_returning(self) -> int:
193+
"""Return 1 if returning, else 0."""
194+
return 1 if self.state == RoborockStateCode.returning_home else 0
195+
196+
@property
197+
def charge_status(self) -> int:
198+
"""Return 1 if charging, else 0."""
199+
return 1 if self.state == RoborockStateCode.charging else 0
200+
184201
def get_status_dict(self) -> dict[str, Any]:
185202
"""Generate status dict using the current simulated state."""
186203
return {
@@ -192,8 +209,8 @@ def get_status_dict(self) -> dict[str, Any]:
192209
"clean_area": 20965000,
193210
"error_code": 0,
194211
"map_present": 1,
195-
"in_cleaning": 1 if self.state == RoborockStateCode.cleaning else 0,
196-
"in_returning": 1 if self.state == RoborockStateCode.returning_home else 0,
212+
"in_cleaning": self.in_cleaning,
213+
"in_returning": self.in_returning,
197214
"in_fresh_state": 1,
198215
"lab_status": 1,
199216
"water_box_status": 1,
@@ -225,10 +242,10 @@ def get_status_dict(self) -> dict[str, Any]:
225242
"collision_avoid_status": 1,
226243
"switch_map_mode": 0,
227244
"dock_error_status": 0,
228-
"charge_status": 1 if self.state == RoborockStateCode.charging else 0,
245+
"charge_status": self.charge_status,
229246
"unsave_map_reason": 0,
230247
"unsave_map_flag": 0,
231-
"dss": 169, # Dock sensor status (bitmask representing water box, dust bag, wash/dry status)
248+
"dss": self.dss,
232249
}
233250

234251
def _handle_app_start(self, params: Any) -> str:

tests/testing/test_v1_simulator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,22 @@ def custom_get_status(params):
152152
await device.v1_properties.status.refresh()
153153
assert device.v1_properties.status.battery == 77
154154
assert device.v1_properties.status.fan_power == 999
155+
156+
157+
async def test_trait_properties_and_dss_config():
158+
"""Verify that properties and dss config are correctly exposed on the simulator."""
159+
fake_device = V1VacuumSimulator(duid="s7_properties", state=RoborockStateCode.cleaning, dss=42)
160+
assert fake_device.in_cleaning == 1
161+
assert fake_device.in_returning == 0
162+
assert fake_device.charge_status == 0
163+
assert fake_device.dss == 42
164+
165+
fake_device.state = RoborockStateCode.returning_home
166+
assert fake_device.in_cleaning == 0
167+
assert fake_device.in_returning == 1
168+
assert fake_device.charge_status == 0
169+
170+
fake_device.state = RoborockStateCode.charging
171+
assert fake_device.in_cleaning == 0
172+
assert fake_device.in_returning == 0
173+
assert fake_device.charge_status == 1

0 commit comments

Comments
 (0)