Skip to content

Commit

Permalink
Reformat history data if returned as a dict/Roborock S7 Support (#989) (
Browse files Browse the repository at this point in the history
#990)

* Reformat history data if returned as a dict/Roborock S7 Support (#989)

* Added Roborock S7 to list of supported devices
  • Loading branch information
fettlaus committed Mar 25, 2021
1 parent e067279 commit 3244224
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ To ease the process of setting up a development environment we have prepared `a
Supported devices
-----------------

- Xiaomi Mi Robot Vacuum V1, S5, M1S
- Xiaomi Mi Robot Vacuum V1, S5, M1S, S7
- Xiaomi Mi Home Air Conditioner Companion
- Xiaomi Mi Smart Air Conditioner A (xiaomi.aircondition.mc1, mc2, mc4, mc5)
- Xiaomi Mi Air Purifier 2, 3H, 3C, Pro (zhimi.airpurifier.m2, mb3, mb4, v7)
Expand Down
47 changes: 47 additions & 0 deletions miio/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,50 @@ def test_timezone(self):

with patch.object(self.device, "send", return_value=0):
assert self.device.timezone() == "UTC"

def test_history(self):
with patch.object(
self.device,
"send",
return_value=[
174145,
2410150000,
82,
[
1488240000,
1488153600,
1488067200,
1487980800,
1487894400,
1487808000,
1487548800,
],
],
):
assert self.device.clean_history().total_duration == datetime.timedelta(
days=2, seconds=1345
)

def test_history_dict(self):
with patch.object(
self.device,
"send",
return_value={
"clean_time": 174145,
"clean_area": 2410150000,
"clean_count": 82,
"dust_collection_count": 5,
"records": [
1488240000,
1488153600,
1488067200,
1487980800,
1487894400,
1487808000,
1487548800,
],
},
):
assert self.device.clean_history().total_duration == datetime.timedelta(
days=2, seconds=1345
)
15 changes: 12 additions & 3 deletions miio/vacuumcontainers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: UTF-8 -*#
from datetime import datetime, time, timedelta
from enum import IntEnum
from typing import Any, Dict, List
from typing import Any, Dict, List, Union

from croniter import croniter

Expand Down Expand Up @@ -184,14 +184,23 @@ def got_error(self) -> bool:
class CleaningSummary(DeviceStatus):
"""Contains summarized information about available cleaning runs."""

def __init__(self, data: List[Any]) -> None:
def __init__(self, data: Union[List[Any], Dict[str, Any]]) -> None:
# total duration, total area, amount of cleans
# [ list, of, ids ]
# { "result": [ 174145, 2410150000, 82,
# [ 1488240000, 1488153600, 1488067200, 1487980800,
# 1487894400, 1487808000, 1487548800 ] ],
# "id": 1 }
self.data = data
# newer models return a dict
if type(data) is dict:
self.data = [
data["clean_time"],
data["clean_area"],
data["clean_count"],
data["records"],
]
else:
self.data = data

@property
def total_duration(self) -> timedelta:
Expand Down

0 comments on commit 3244224

Please sign in to comment.