Skip to content

Commit

Permalink
vacuum: is_on should be true for segment cleaning (#688)
Browse files Browse the repository at this point in the history
* vacuum: is_on should be true for segment cleaning

* Fixes #687
* Remove deprecated in_cleaning, dnd

* docstring update for is_on

* fix tests
  • Loading branch information
rytilahti authored Apr 29, 2020
1 parent 85e119c commit 95bdf27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
1 change: 0 additions & 1 deletion miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def test_status(self):

status = self.status()
assert status.is_on is False
assert status.dnd is True
assert status.clean_time == datetime.timedelta()
assert status.error_code == 0
assert status.error == "No error"
Expand Down
34 changes: 17 additions & 17 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import IntEnum
from typing import Any, Dict, List

from .utils import deprecated, pretty_seconds, pretty_time
from .utils import pretty_seconds, pretty_time


def pretty_area(x: float) -> float:
Expand Down Expand Up @@ -57,6 +57,15 @@ def __init__(self, data: Dict[str, Any]) -> None:
# "dnd_enabled":0,"begin_time":1534333389,"clean_time":21,
# "clean_area":202500,"clean_trigger":2,"back_trigger":0,
# "completed":0,"clean_strategy":1}

# Example of S6 in the segment cleaning mode
# new items: in_fresh_state, water_box_status, lab_status, map_status, lock_status
#
# [{'msg_ver': 2, 'msg_seq': 28, 'state': 18, 'battery': 95,
# 'clean_time': 606, 'clean_area': 8115000, 'error_code': 0,
# 'map_present': 1, 'in_cleaning': 3, 'in_returning': 0,
# 'in_fresh_state': 0, 'lab_status': 1, 'water_box_status': 0,
# 'fan_power': 102, 'dnd_enabled': 0, 'map_status': 3, 'lock_status': 0}]
self.data = data

@property
Expand Down Expand Up @@ -127,44 +136,35 @@ def clean_area(self) -> float:
"""Cleaned area in m2."""
return pretty_area(self.data["clean_area"])

@property
@deprecated("Use vacuum's dnd_status() instead, which is more accurate")
def dnd(self) -> bool:
"""DnD status. Use :func:`vacuum.dnd_status` instead of this."""
return bool(self.data["dnd_enabled"])

@property
def map(self) -> bool:
"""Map token."""
return bool(self.data["map_present"])

@property
@deprecated("See is_on")
def in_cleaning(self) -> bool:
"""True if currently cleaning. Please use :func:`is_on` instead of this."""
return self.is_on
# we are not using in_cleaning as it does not seem to work properly.
# return bool(self.data["in_cleaning"])

@property
def in_zone_cleaning(self) -> bool:
"""Return True if the vacuum is in zone cleaning mode."""
return self.data["in_cleaning"] == 2

@property
def in_segment_cleaning(self) -> bool:
"""Return True if the vacuum is in segment cleaning mode."""
return self.data["in_cleaning"] == 3

@property
def is_paused(self) -> bool:
"""Return True if vacuum is paused."""
return self.state_code == 10

@property
def is_on(self) -> bool:
"""True if device is currently cleaning (either automatic, manual,
spot, or zone)."""
"""True if device is currently cleaning in any mode."""
return (
self.state_code == 5
or self.state_code == 7
or self.state_code == 11
or self.state_code == 17
or self.state_code == 18
)

@property
Expand Down

0 comments on commit 95bdf27

Please sign in to comment.