Skip to content

Commit

Permalink
Xiaomi vacuum. Add property for water box (water tank) attach status (r…
Browse files Browse the repository at this point in the history
…ytilahti#675)

* Add property for water box (water tank) attach status

* Add test for "is_water_box_attached"

* Update doc

* Avoid crash if vaccum doesn't support water box

Co-Authored-By: Teemu R. <tpr@iki.fi>

* Fix return type of is_water_box_attached

Co-Authored-By: Teemu R. <tpr@iki.fi>

Co-authored-by: Teemu R. <tpr@iki.fi>
  • Loading branch information
2 people authored and xvlady committed May 9, 2021
1 parent 6e40d90 commit c1bee7b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions docs/vacuum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ Status reporting
Fanspeed: 60
Cleaning since: 0:00:00
Cleaned area: 0.0 m²
DND enabled: 0
Map present: 1
in_cleaning: 0
Water box attached: False

Start cleaning
~~~~~~~~~~~~~~
Expand Down
2 changes: 2 additions & 0 deletions miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, *args, **kwargs):
"battery": 100,
"fan_power": 20,
"msg_seq": 320,
"water_box_status": 1,
}

self.return_values = {
Expand Down Expand Up @@ -94,6 +95,7 @@ def test_status(self):
assert status.error == "No error"
assert status.fanspeed == self.device.start_state["fan_power"]
assert status.battery == self.device.start_state["battery"]
assert status.is_water_box_attached is True

def test_status_with_errors(self):
errors = {5: "Clean main brush", 19: "Unpowered charging station"}
Expand Down
1 change: 1 addition & 0 deletions miio/vacuum_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def status(vac: miio.Vacuum):
# click.echo("DND enabled: %s" % res.dnd)
# click.echo("Map present: %s" % res.map)
# click.echo("in_cleaning: %s" % res.in_cleaning)
click.echo("Water box attached: %s" % res.is_water_box_attached)


@cli.command()
Expand Down
5 changes: 5 additions & 0 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ def is_on(self) -> bool:
or self.state_code == 17
)

@property
def is_water_box_attached(self) -> bool:
"""Return True is water box is installed."""
return "water_box_status" in self.data and self.data["water_box_status"] == 1

@property
def got_error(self) -> bool:
"""True if an error has occured."""
Expand Down

0 comments on commit c1bee7b

Please sign in to comment.