Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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