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

fan: Ability to disable delayed turn off functionality #741

Merged
merged 3 commits into from
Jun 30, 2020
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
4 changes: 2 additions & 2 deletions miio/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def set_child_lock(self, lock: bool):
def delay_off(self, seconds: int):
"""Set delay off seconds."""

if seconds < 1:
if seconds < 0:
raise FanException("Invalid value for a delayed turn off: %s" % seconds)

return self.send("set_poweroff_time", [seconds])
Expand Down Expand Up @@ -755,7 +755,7 @@ def set_child_lock(self, lock: bool):
def delay_off(self, minutes: int):
"""Set delay off minutes."""

if minutes < 1:
if minutes < 0:
raise FanException("Invalid value for a delayed turn off: %s" % minutes)

return self.send("s_t_off", [minutes])
Expand Down
20 changes: 8 additions & 12 deletions miio/tests/test_fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,12 @@ def delay_off_countdown():
assert delay_off_countdown() == 100
self.device.delay_off(200)
assert delay_off_countdown() == 200
self.device.delay_off(0)
assert delay_off_countdown() == 0

with pytest.raises(FanException):
self.device.delay_off(-1)

with pytest.raises(FanException):
self.device.delay_off(0)


class DummyFanV3(DummyDevice, Fan):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -513,13 +512,12 @@ def delay_off_countdown():
assert delay_off_countdown() == 100
self.device.delay_off(200)
assert delay_off_countdown() == 200
self.device.delay_off(0)
assert delay_off_countdown() == 0

with pytest.raises(FanException):
self.device.delay_off(-1)

with pytest.raises(FanException):
self.device.delay_off(0)


class DummyFanSA1(DummyDevice, Fan):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -729,13 +727,12 @@ def delay_off_countdown():
assert delay_off_countdown() == 100
self.device.delay_off(200)
assert delay_off_countdown() == 200
self.device.delay_off(0)
assert delay_off_countdown() == 0

with pytest.raises(FanException):
self.device.delay_off(-1)

with pytest.raises(FanException):
self.device.delay_off(0)


class DummyFanP5(DummyDevice, FanP5):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -912,9 +909,8 @@ def delay_off_countdown():
assert delay_off_countdown() == 100
self.device.delay_off(200)
assert delay_off_countdown() == 200
self.device.delay_off(0)
assert delay_off_countdown() == 0

with pytest.raises(FanException):
self.device.delay_off(-1)

with pytest.raises(FanException):
self.device.delay_off(0)