Skip to content

Commit

Permalink
heater: add support leshow.heater.nfj3lx
Browse files Browse the repository at this point in the history
  • Loading branch information
st7105 committed Oct 4, 2023
1 parent 2ba0b51 commit 081a911
Showing 1 changed file with 68 additions and 1 deletion.
69 changes: 68 additions & 1 deletion miio/integrations/zhimi/heater/heater_miot.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@
# Indicator light (siid=7)
"led_brightness": {"siid": 7, "piid": 1},
},
"leshow.heater.nfj3lx": {
# Source https://miot-spec.org/miot-spec-v2/instance?type=urn:miot-spec-v2:device:heater:0000A01A:leshow-nfj3lx:1
# Heater (siid=2)
"power": {"siid": 2, "piid": 1},
"fault": {"siid": 2, "piid": 2},
"mode": {"siid": 2, "piid": 5},
"target_temperature": {"siid": 2, "piid": 3},
# Countdown (siid=3)
"countdown_time": {"siid": 3, "piid": 1},
# Environment (siid=4)
"temperature": {"siid": 4, "piid": 7},
# Physical Control Locked (siid=5)
"child_lock": {"siid": 5, "piid": 1},
# Alarm (siid=6)
"buzzer": {"siid": 6, "piid": 1},
# Indicator light (siid=7)
"led_brightness": {"siid": 7, "piid": 1},
"sway": {"siid": 8, "piid": 1}
},
}

HEATER_PROPERTIES = {
Expand All @@ -80,6 +99,21 @@ class LedBrightness(enum.Enum):
Dim = 2


class Mode(enum.Enum):
ConstantTemperature = 0
Heat = 1
Warm = 2
NaturalWind = 3


class DeviceFault(enum.Enum):
NoFaults = 0
EnvTempIsTooLow = 1
EnvTempIsTooHigh = 2
PlugTempIsTooLow = 3
PlugTempIsTooHigh = 4


class HeaterMiotStatus(DeviceStatus):
"""Container for status reports from the Xiaomi Smart Space Heater S and 1S."""

Expand Down Expand Up @@ -138,7 +172,7 @@ def child_lock(self) -> bool:
@property
def buzzer(self) -> bool:
"""True if buzzer is turned on, False otherwise."""
return self.data["buzzer"] is True
return self.data["buzzer"] is True or self.data["buzzer"] is 1

@property
def led_brightness(self) -> LedBrightness:
Expand All @@ -148,6 +182,20 @@ def led_brightness(self) -> LedBrightness:
value = 3 - value
return LedBrightness(value)

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

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

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


class HeaterMiot(MiotDevice):
"""Main class representing the Xiaomi Smart Space Heater S (zhimi.heater.mc2) & 1S
Expand Down Expand Up @@ -241,6 +289,25 @@ def set_led_brightness(self, brightness: LedBrightness):
raise ValueError("Unsupported brightness Dim for model '%s'.", self.model)
return self.set_property("led_brightness", value)

@command(
click.argument("mode", type=EnumType(Mode)),
default_output=format_output(
"Setting Mode to {mode}"
),
)
def set_mode(self, mode: Mode):
value = mode.value
return self.set_property("mode", value)

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

@command(
click.argument("seconds", type=int),
default_output=format_output("Setting delayed turn off to {seconds} seconds"),
Expand Down

0 comments on commit 081a911

Please sign in to comment.