Skip to content

Commit

Permalink
Implement code review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Dec 28, 2022
1 parent de2a473 commit 32f820d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
16 changes: 12 additions & 4 deletions miio/integrations/vacuum/roborock/tests/test_vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ def test_set_mop_dryer_enabled_model_check(self):
def test_set_mop_dryer_dry_time_model_check(self):
"""Test Roborock S7 check when setting mop dryer dry time."""
with pytest.raises(UnsupportedFeatureException):
self.device.set_mop_dryer_dry_time(dry_time=2)
self.device.set_mop_dryer_dry_time(dry_time_seconds=10800)

def test_start_mop_drying_model_check(self):
"""Test Roborock S7 check when starting mop drying."""
Expand Down Expand Up @@ -528,15 +528,23 @@ def test_mop_dryer_is_drying(self):

def test_mop_dryer_remaining_seconds(self):
"""Test getting mop dryer remaining seconds."""
assert self.device.status().mop_dryer_remaining_seconds == 3600
assert self.device.status().mop_dryer_remaining_seconds == datetime.timedelta(
seconds=3600
)

def test_set_mop_dryer_enabled_model_check(self):
"""Test setting mop dryer enabled."""
assert self.device.set_mop_dryer_enabled(enabled=True)
with patch.object(self.device, "send", return_value=["ok"]) as mock_method:
assert self.device.set_mop_dryer_enabled(enabled=False)
mock_method.assert_called_once_with("app_set_dryer_setting", {"status": 0})

def test_set_mop_dryer_dry_time_model_check(self):
"""Test setting mop dryer dry time."""
assert self.device.set_mop_dryer_dry_time(dry_time=2)
with patch.object(self.device, "send", return_value=["ok"]) as mock_method:
assert self.device.set_mop_dryer_dry_time(dry_time_seconds=14400)
mock_method.assert_called_once_with(
"app_set_dryer_setting", {"on": {"dry_time": 14400}}
)

def test_start_mop_drying_model_check(self):
"""Test starting mop drying."""
Expand Down
11 changes: 4 additions & 7 deletions miio/integrations/vacuum/roborock/vacuum.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,11 +965,6 @@ def _verify_mop_dryer_supported(self) -> None:
if self.model not in [ROCKROBO_S7, ROCKROBO_S7_MAXV]:
raise UnsupportedFeatureException("Dryer not supported by %s", self.model)

# check if `dry_status` attribute is in status response
# this a good indication if the add-on has been installed
if self.status().is_mop_drying is None:
raise UnsupportedFeatureException("Mop dryer add-on not installed")

@command()
def mop_dryer_settings(self) -> MopDryerSettings:
"""Get mop dryer settings."""
Expand All @@ -983,11 +978,13 @@ def set_mop_dryer_enabled(self, enabled: bool) -> bool:
return self.send("app_set_dryer_setting", {"status": int(enabled)})[0] == "ok"

@command(click.argument("dry_time", type=int))
def set_mop_dryer_dry_time(self, dry_time: int) -> bool:
def set_mop_dryer_dry_time(self, dry_time_seconds: int) -> bool:
"""Set mop dryer add-on dry time."""
self._verify_mop_dryer_supported()
return (
self.send("app_set_dryer_setting", {"on": {"dry_time": dry_time * 3600}})[0]
self.send("app_set_dryer_setting", {"on": {"dry_time": dry_time_seconds}})[
0
]
== "ok"
)

Expand Down
16 changes: 8 additions & 8 deletions miio/integrations/vacuum/roborock/vacuumcontainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ def is_mop_drying(self) -> Optional[bool]:
entity_category="diagnostic",
enabled_default=False,
)
def mop_dryer_remaining_seconds(self) -> Optional[int]:
def mop_dryer_remaining_seconds(self) -> Optional[timedelta]:
"""Return remaining mop drying seconds."""
if "rdt" in self.data:
return self.data["rdt"]
return pretty_seconds(self.data["rdt"])
return None


Expand Down Expand Up @@ -1006,13 +1006,13 @@ def enabled(self) -> bool:
"Mop dry time",
setter_name="set_mop_dryer_dry_time",
icon="mdi:fan",
unit="hour",
min_value=2,
max_value=4,
step=1,
unit="s",
min_value=7200,
max_value=14400,
step=3600,
entity_category="config",
enabled_default=False,
)
def dry_time(self) -> bool:
def dry_time(self) -> timedelta:
"""Return mop dry time."""
return self.data["on"]["dry_time"] * 3600
return pretty_seconds(self.data["on"]["dry_time"])

0 comments on commit 32f820d

Please sign in to comment.