Skip to content

Commit

Permalink
fan: Ability to disable delayed turn off functionality (#741)
Browse files Browse the repository at this point in the history
* Added ability to disable delayed turn off functionality

When 0 is passed, delay turn off is disabled. Before this, if delay off was set, it could not be unset.

* Update test_fan.py

* Update test_fan.py
  • Loading branch information
insajd committed Jun 30, 2020
1 parent c6702ad commit 1bb5113
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
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)

0 comments on commit 1bb5113

Please sign in to comment.