diff --git a/miio/__init__.py b/miio/__init__.py index d304229d5..8cbe6dba7 100644 --- a/miio/__init__.py +++ b/miio/__init__.py @@ -52,6 +52,7 @@ ) from miio.viomivacuum import ViomiVacuum from miio.waterpurifier import WaterPurifier +from miio.waterheater import WaterHeater from miio.wifirepeater import WifiRepeater from miio.wifispeaker import WifiSpeaker from miio.yeelight import Yeelight diff --git a/miio/discovery.py b/miio/discovery.py index 7e2b55275..55109aaeb 100644 --- a/miio/discovery.py +++ b/miio/discovery.py @@ -38,6 +38,7 @@ Vacuum, ViomiVacuum, WaterPurifier, + WaterHeater, WifiRepeater, WifiSpeaker, Yeelight, @@ -129,6 +130,7 @@ AirHumidifierMjjsq, model=MODEL_HUMIDIFIER_MJJSQ ), "yunmi-waterpuri-v2": WaterPurifier, + "viomi-waterheater-e1": WaterHeater, "philips-light-bulb": PhilipsBulb, # cannot be discovered via mdns "philips-light-hbulb": PhilipsWhiteBulb, # cannot be discovered via mdns "philips-light-candle": PhilipsBulb, # cannot be discovered via mdns diff --git a/miio/waterheater.py b/miio/waterheater.py new file mode 100644 index 000000000..cd8ba7638 --- /dev/null +++ b/miio/waterheater.py @@ -0,0 +1,133 @@ +import logging +from typing import Any, Dict + +from .click_common import command, format_output +from .device import Device + +_LOGGER = logging.getLogger(__name__) + + +class WaterHeaterStatus: + + def __init__(self, data: Dict[str, Any]) -> None: + self.data = data + + @property + def washStatus(self) -> str: + return self.data["washStatus"] + + @property + def velocity(self) -> str: + return self.data["velocity"] + + @property + def waterTemp(self) -> str: + return self.data["waterTemp"] + + @property + def targetTemp(self) -> str: + return self.data["targetTemp"] + + @property + def errStatus(self) -> str: + return self.data["errStatus"] + + @property + def hotWater(self) -> str: + return self.data["hotWater"] + + @property + def needClean(self) -> str: + return self.data["needClean"] + + @property + def modeType(self) -> str: + return self.data["modeType"] + + @property + def appointStart(self) -> str: + return self.data["appointStart"] + + @property + def appointEnd(self) -> str: + return self.data["appointEnd"] + + def __repr__(self) -> str: + return ( + "" + % ( + self.washStatus, + self.velocity, + self.waterTemp, + self.targetTemp, + self.errStatus, + self.hotWater, + self.needClean, + self.modeType, + self.appointStart, + self.appointEnd, + ) + ) + + def __json__(self): + return self.data + + +class WaterHeater(Device): + """Main class representing the waiter purifier.""" + + @command( + default_output=format_output( + "", + "Status: {result.washStatus}\n" + "Velocity: {result.velocity}\n" + "Water temperature: {result.waterTemp}\n" + "Target temperature: {result.targetTemp}\n" + "Error status: {result.errStatus}\n" + "Hot Water: {result.hotWater}\n" + "Need Clean: {result.needClean}\n" + "Mode Type: {result.modeType}\n" + "Appoint Start: {result.appointStart}\n" + "Appoint End: {result.appointEnd}\n", + ) + ) + def status(self) -> WaterHeaterStatus: + """Retrieve properties.""" + + properties = [ + "washStatus", + "velocity", + "waterTemp", + "targetTemp", + "errStatus", + "hotWater", + "needClean", + "modeType", + "appointStart", + "appointEnd", + ] + + _props_per_request = 1 + values = self.get_properties(properties, max_properties=_props_per_request) + + return WaterHeaterStatus(dict(zip(properties, values))) + + @command(default_output=format_output("Powering on")) + def on(self): + """Power on.""" + return self.send("set_power", [1]) + + @command(default_output=format_output("Powering off")) + def off(self): + """Power off.""" + return self.send("set_power", [0])