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 xiaomi smart wifi socket added #29

Merged
merged 11 commits into from
Jul 21, 2017
Merged
28 changes: 28 additions & 0 deletions mirobo/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ def pretty_time(x: int) -> datetime:
}


class PlugStatus:
"""Container for status reports from the plug."""
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"

@property
def temperature(self) -> float:
return self.data["temperature"]

@property
def current(self) -> float:
return self.data["current"]

def __str__(self) -> str:
s = "<PlugStatus power=%s, temperature=%s, current=%s>" % (self.state,
self.temperature,

Choose a reason for hiding this comment

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

line too long (84 > 79 characters)

self.current)

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

return s
Copy link
Owner

Choose a reason for hiding this comment

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

I think:

s = "<PlugStatus power=%s, temperature=%s, current=%s>" % (self.state,
self.temperature,
self.current)

Properly intended would look nicer, but this is fine too.



class VacuumStatus:
"""Container for status reports from the vacuum."""
def __init__(self, data: Dict[str, Any]) -> None:
Expand Down
23 changes: 23 additions & 0 deletions mirobo/plug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .device import Device
from .containers import PlugStatus


class Plug(Device):

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

Choose a reason for hiding this comment

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

expected 2 blank lines, found 1

"""Main class representing the smart wifi socket / plug."""

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

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

def status(self):
"""Retrieve properties."""
properties = ['power', 'temperature', 'current']
values = self.send(
"get_prop",
properties
)
return PlugStatus(dict(zip(properties, values)))
3 changes: 2 additions & 1 deletion mirobo/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
_LOGGER = logging.getLogger(__name__)

# Map of device ids
xiaomi_devices_reverse = {0x02f2: "Xiaomi Mi Robot Vacuum",
xiaomi_devices_reverse = {0x02c1: "Xiaomi Mi Smart WiFi Socket",
0x02f2: "Xiaomi Mi Robot Vacuum",
0x00c4: "Xiaomi Smart Mi Air Purifier",
0x031a: "Xiaomi Smart home gateway",
0x0330: "Yeelight color bulb"
Expand Down