Skip to content

Commit

Permalink
heater: change to enum buzzer and sway
Browse files Browse the repository at this point in the history
  • Loading branch information
st7105 committed Oct 4, 2023
1 parent eba666d commit 05bbb6f
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions miio/integrations/zhimi/heater/heater_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,24 @@
"temperature_range": (16, 28),
"delay_off_range": (0, 8 * 3600),
},
"leshow.heater.nfj3lx": {
"temperature_range": (22, 28),
"delay_off_range": (0, 8 * 3600),
},
}


class LedBrightness(enum.Enum):
"""Note that only Xiaomi Smart Space Heater 1S (zhimi.heater.za2) supports `Dim`."""
class Buzzer(enum.Enum):
Off = 0
On = 1


class Sway(enum.Enum):
Off = 0
On = 1


class LedBrightness(enum.Enum):
On = 0
Off = 1
Dim = 2
Expand Down Expand Up @@ -169,11 +181,6 @@ def child_lock(self) -> bool:
"""True if child lock is on, False otherwise."""
return self.data["child_lock"] is True

@property
def buzzer(self) -> bool:
"""True if buzzer is turned on, False otherwise."""
return self.data["buzzer"] is True or self.data["buzzer"] is 1

@property
def led_brightness(self) -> LedBrightness:
"""LED indicator brightness."""
Expand All @@ -193,8 +200,14 @@ def fault(self) -> DeviceFault:
return DeviceFault(value)

@property
def is_sway(self) -> bool:
return self.data["sway"] is True or self.data["sway"] is 1
def buzzer(self) -> Buzzer:
value = self.data["buzzer"]
return Buzzer(value)

@property
def sway(self) -> Sway:
value = self.data["sway"]
return Sway(value)


class HeaterMiot(MiotDevice):
Expand Down Expand Up @@ -265,14 +278,14 @@ def set_child_lock(self, lock: bool):
return self.set_property("child_lock", lock)

@command(
click.argument("buzzer", type=bool),
click.argument("buzzer", type=EnumType(Buzzer)),
default_output=format_output(
lambda buzzer: "Turning on buzzer" if buzzer else "Turning off buzzer"
"Setting buzzer to {buzzer}"
),
)
def set_buzzer(self, buzzer: bool):
"""Set buzzer on/off."""
return self.set_property("buzzer", buzzer)
def set_buzzer(self, buzzer: Buzzer):
value = buzzer.value
return self.set_property("buzzer", value)

@command(
click.argument("brightness", type=EnumType(LedBrightness)),
Expand Down Expand Up @@ -300,13 +313,14 @@ def set_mode(self, mode: Mode):
return self.set_property("mode", value)

@command(
click.argument("sway", type=bool),
click.argument("sway", type=EnumType(Sway)),
default_output=format_output(
lambda buzzer: "Turning on sway" if buzzer else "Turning off sway"
"Setting sway to {sway}"
),
)
def set_sway(self, sway: bool):
return self.set_property("sway", sway)
def set_sway(self, sway: Sway):
value = sway.value
return self.set_property("sway", value)

@command(
click.argument("seconds", type=int),
Expand Down

0 comments on commit 05bbb6f

Please sign in to comment.