Skip to content

Commit 0e28988

Browse files
authored
feat: Add property for accessing the current map from the status object (#433)
* feat: Add property for accessing the current map from the status object * fix: add test where current_map is none
1 parent 381acf6 commit 0e28988

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

roborock/containers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,13 @@ def get_mop_mode_code(self, mop_mode: str) -> int:
425425
raise RoborockException("Attempted to get mop_mode before status has been updated.")
426426
return self.mop_mode.as_dict().get(mop_mode)
427427

428+
@property
429+
def current_map(self) -> int | None:
430+
"""Returns the current map ID if the map is present."""
431+
if self.map_status is not None:
432+
return (self.map_status - 3) // 4
433+
return None
434+
428435

429436
@dataclass
430437
class S4MaxStatus(Status):

tests/test_containers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ def test_status():
234234
assert s.fan_power == 102
235235
assert s.dnd_enabled == 0
236236
assert s.map_status == 3
237+
assert s.current_map == 0
237238
assert s.is_locating == 0
238239
assert s.lock_status == 0
239240
assert s.water_box_mode == 203
@@ -262,6 +263,22 @@ def test_status():
262263
assert s.water_box_mode == RoborockMopIntensityS7.intense
263264

264265

266+
def test_current_map() -> None:
267+
"""Test the current map logic based on map status."""
268+
s = S7MaxVStatus.from_dict(STATUS)
269+
assert s.map_status == 3
270+
assert s.current_map == 0
271+
272+
s.map_status = 7
273+
assert s.current_map == 1
274+
275+
s.map_status = 11
276+
assert s.current_map == 2
277+
278+
s.map_status = None
279+
assert not s.current_map
280+
281+
265282
def test_dnd_timer():
266283
dnd = DnDTimer.from_dict(DND_TIMER)
267284
assert dnd.start_hour == 22

0 commit comments

Comments
 (0)