Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device support for the chuangmi plug v1 added #33

Merged
merged 5 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mirobo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from mirobo.vacuumcontainers import VacuumStatus, ConsumableStatus, CleaningDetails, CleaningSummary, Timer
from mirobo.vacuum import Vacuum, VacuumException
from mirobo.plug import Plug
from mirobo.plug_v1 import PlugV1
from mirobo.airpurifier import AirPurifier
from mirobo.strip import Strip
from mirobo.device import Device, DeviceException
55 changes: 55 additions & 0 deletions mirobo/plug_v1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from .device import Device
from typing import Any, Dict


class PlugV1(Device):
"""Main class representing the chuangmi plug v1."""

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

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

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

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

def status(self):
"""Retrieve properties."""
properties = ['on', 'usb_on']
values = self.send(
"get_prop",
properties
)
return PlugV1Status(dict(zip(properties, values)))


class PlugV1Status:
"""Container for status reports from the plug."""
def __init__(self, data: Dict[str, Any]) -> None:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'Dict'
undefined name 'Any'

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An example would also be nice here :-) Are those values already booleans or should they be converted below?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

@rytilahti rytilahti Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, sorry for that, too many PRs got me confused. However, I think we can already merge this after fixing the conflict and update the information when we receive it. Btw, here's someone with the purifier, so at least we can get it tested easily, I hope: https://community.home-assistant.io/t/xiaomi-mi-air-purifier-support/14228/12

self.data = data

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

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

@property
def usb_power(self) -> bool:
return self.data["usb_on"]

def __str__(self) -> str:
s = "<PlugV1Status power=%s, usb_power=%s>" % \
(self.power,
self.usb_power)
return s