Skip to content

Commit

Permalink
Fix PTC support of the dmaker.airfresh.t2017 (rytilahti#853)
Browse files Browse the repository at this point in the history
  • Loading branch information
syssi authored and xvlady committed May 9, 2021
1 parent 06506f8 commit 79331b6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion miio/airfresh_t2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class OperationMode(enum.Enum):


class PtcLevel(enum.Enum):
Off = "off"
Low = "low"
Medium = "medium"
High = "high"
Expand Down Expand Up @@ -320,6 +319,16 @@ def set_display_orientation(self, orientation: DisplayOrientation):
"""Set display orientation."""
return self.send("set_screen_direction", [orientation.value])

@command(
click.argument("ptc", type=bool),
default_output=format_output(
lambda led: "Turning on ptc" if led else "Turning off ptc"
),
)
def set_ptc(self, ptc: bool):
"""Turn ptc on/off."""
return self.send("set_ptc_on", [ptc])

@command(
click.argument("level", type=EnumType(PtcLevel)),
default_output=format_output("Setting ptc level to '{level.value}'"),
Expand Down
13 changes: 11 additions & 2 deletions miio/tests/test_airfresh_t2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def __init__(self, *args, **kwargs):
"set_display": lambda x: self._set_state("display", [(x[0] == "on")]),
"set_screen_direction": lambda x: self._set_state("screen_direction", x),
"set_ptc_level": lambda x: self._set_state("ptc_level", x),
"set_ptc_on": lambda x: self._set_state("ptc_on", x),
"set_favourite_speed": lambda x: self._set_state("favourite_speed", x),
"set_filter_reset": lambda x: self._set_filter_reset(x),
}
Expand Down Expand Up @@ -201,12 +202,20 @@ def favorite_speed():
with pytest.raises(AirFreshException):
self.device.set_favorite_speed(301)

def test_set_ptc(self):
def ptc():
return self.device.status().ptc

self.device.set_ptc(True)
assert ptc() is True

self.device.set_ptc(False)
assert ptc() is False

def test_set_ptc_level(self):
def ptc_level():
return self.device.status().ptc_level

self.device.set_ptc_level(PtcLevel.Off)
assert ptc_level() == PtcLevel.Off
self.device.set_ptc_level(PtcLevel.Low)
assert ptc_level() == PtcLevel.Low
self.device.set_ptc_level(PtcLevel.Medium)
Expand Down

0 comments on commit 79331b6

Please sign in to comment.