Skip to content

Commit

Permalink
Initial support for viomi.waterheater.e1 devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuz666 committed Oct 11, 2020
1 parent c4ab5e6 commit eba32aa
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions miio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions miio/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Vacuum,
ViomiVacuum,
WaterPurifier,
WaterHeater,
WifiRepeater,
WifiSpeaker,
Yeelight,
Expand Down Expand Up @@ -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
Expand Down
133 changes: 133 additions & 0 deletions miio/waterheater.py
Original file line number Diff line number Diff line change
@@ -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 (
"<WaterHeaterStatus "
"washStatus=%s, "
"velocity=%s, "
"waterTemp=%s, "
"targetTemp=%s, "
"errStatus=%s, "
"hotWater=%s, "
"needClean=%s, "
"modeType=%s, "
"appointStart=%s, "
"appointEnd=%s>"
% (
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])

0 comments on commit eba32aa

Please sign in to comment.