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
37 changes: 37 additions & 0 deletions mirobo/plug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from .device import Device

PROPERTY_POWER = 'power'
PROPERTY_TEMPERATURE = 'temperature'
PROPERTY_CURRENT = 'current'


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 __init__(self, ip: str, token: str, start_id: int = 0, debug: int = 0) -> None:

Choose a reason for hiding this comment

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

line too long (87 > 79 characters)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't want to fix this. ;-)

Copy link
Owner

Choose a reason for hiding this comment

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

Fair enough, I think hound should complain first after 100 characters..

super().__init__(ip, token, start_id, debug)
self.manual_seqnum = -1
Copy link
Owner

Choose a reason for hiding this comment

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

Is the __init__ here unnecessary though, it just sets the manual_seqnum it never uses :-)


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."""
status = self.send(

Choose a reason for hiding this comment

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

multiple spaces after operator

"get_prop",
[ PROPERTY_POWER, PROPERTY_TEMPERATURE, PROPERTY_CURRENT ]

Choose a reason for hiding this comment

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

whitespace after '['
whitespace before ']'

)
return {
PROPERTY_POWER: status[0],
PROPERTY_TEMPERATURE: status[1],
PROPERTY_CURRENT: status[2]
}
Copy link
Owner

Choose a reason for hiding this comment

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

What type of data is returned by these? Would it make sense to wrap it inside a class like PlugStatus?


def raw_command(self, cmd, params):
"""Send a raw command to the device."""
return self.send(cmd, params)
Copy link
Owner

Choose a reason for hiding this comment

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

Is raw_command necessary when send() could be used directly?

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