Skip to content

Commit

Permalink
First draft of the water purifier support (#67)
Browse files Browse the repository at this point in the history
* First draft of the water purifier support.

* Small glitch fixed.

* Missing import added.

* Unused import removed.

* README.m updated.
  • Loading branch information
syssi authored and rytilahti committed Sep 9, 2017
1 parent a4d85a1 commit 3266e0f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Thanks for the nice people over [ioBroker forum](http://forum.iobroker.net/viewt
## Supported devices

* Xiaomi Mi Robot Vacuum
* Xiaomi Mi Air Purifier 2
* Xiaomi Mi Air Purifier Pro & Air Purifier 2
* Xiaomi Mi Smart WiFi Socket
* Xiaomi Mi Smart Socket Plug (1 Socket, 1 USB Port)
* Xiaomi Smart Power Strip (WiFi, 6 Ports)
Expand All @@ -23,6 +23,8 @@ Thanks for the nice people over [ioBroker forum](http://forum.iobroker.net/viewt
* Xiaomi Philips LED Ball Lamp
* Xiaomi Universal IR Remote Controller (Chuangmi IR)
* Xiaomi Mi Smart Fan
* Xiaomi Mi Air Humidifer
* Xiaomi Mi Water Purifier (Basic support: Turn on & off)
* Yeelight light bulbs (only a very rudimentary support, use [python-yeelight](https://gitlab.com/stavros/python-yeelight/) for a more complete support)

*Feel free to create a pull request to add support for new devices as well as additional features for supported devices.*
Expand Down
1 change: 1 addition & 0 deletions mirobo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from mirobo.plug_v1 import PlugV1
from mirobo.airpurifier import AirPurifier
from mirobo.airhumidifier import AirHumidifier
from mirobo.waterpurifier import WaterPurifier
from mirobo.strip import Strip
from mirobo.ceil import Ceil
from mirobo.philips_eyecare import PhilipsEyecare
Expand Down
4 changes: 2 additions & 2 deletions mirobo/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import inspect
import codecs
from . import (Device, Vacuum, Plug, PlugV1, Strip, AirPurifier, Ceil,
PhilipsEyecare, ChuangmiIr, AirHumidifier)
PhilipsEyecare, ChuangmiIr, AirHumidifier, WaterPurifier)
from typing import Union, Callable, Dict, Optional # noqa: F401


Expand All @@ -26,7 +26,7 @@
"zhimi-airpurifier-v6": AirPurifier,
"chuangmi-ir-v2": ChuangmiIr,
"zhimi-humidifier-v1": AirHumidifier,
# "yunmi-waterpuri-v2": WaterPurifier,
"yunmi-waterpuri-v2": WaterPurifier,
# It looks like philips devices cannot be discovered via mdns
"philips-light-bulb": Ceil,
"philips-light-ceil": Ceil,
Expand Down
57 changes: 57 additions & 0 deletions mirobo/waterpurifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import logging
from typing import Any, Dict
from collections import defaultdict
from .device import Device

_LOGGER = logging.getLogger(__name__)


class WaterPurifier(Device):
"""Main class representing the waiter purifier."""

def status(self):
"""Retrieve properties."""

properties = ['power']

values = self.send(
"get_prop",
properties
)

properties_count = len(properties)
values_count = len(values)
if properties_count != values_count:
_LOGGER.debug(
"Count (%s) of requested properties does not match the "
"count (%s) of received values.",
properties_count, values_count)

return WaterPurifierStatus(
defaultdict(lambda: None, zip(properties, values)))

def on(self):
"""Power on."""
return self.send("set_power", ["on"])

def off(self):
"""Power off."""
return self.send("set_power", ["off"])


class WaterPurifierStatus:
"""Container for status reports from the water purifier."""

def __init__(self, data: Dict[str, Any]) -> None:
self.data = data

@property
def power(self) -> str:
return self.data["power"]

@property
def is_on(self) -> bool:
return self.power == "on"

def __str__(self) -> str:
return "<WaterPurifierStatus power=%s>" % self.power

0 comments on commit 3266e0f

Please sign in to comment.