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

Device support for the xiaomi smart wifi socket added #29

merged 11 commits into from
Jul 21, 2017

Conversation

syssi
Copy link
Collaborator

@syssi syssi commented Jul 19, 2017

No description provided.

mirobo/plug.py Outdated
def status(self):
"""Retrieve properties."""
status = self.send("get_prop", [PROPERTY_POWER, PROPERTY_TEMPERATURE, PROPERTY_CURRENT])
return {PROPERTY_POWER: status[0], PROPERTY_TEMPERATURE: status[1], PROPERTY_CURRENT: status[2]}

Choose a reason for hiding this comment

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

line too long (104 > 79 characters)

mirobo/plug.py Outdated

def status(self):
"""Retrieve properties."""
status = self.send("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.

multiple spaces after operator
line too long (97 > 79 characters)

mirobo/plug.py Outdated
class Plug(Device):
"""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..

mirobo/plug.py Outdated
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

mirobo/plug.py Outdated
@@ -0,0 +1,29 @@
from .device import Device, DeviceException

Choose a reason for hiding this comment

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

'.device.DeviceException' imported but unused

mirobo/plug.py Outdated
"""Retrieve properties."""
status = self.send(
"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 ']'

mirobo/plug.py Outdated

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

Copy link
Owner

@rytilahti rytilahti left a comment

Choose a reason for hiding this comment

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

Looks good! Have you thought how this could look from the side of the console client?

mirobo/plug.py Outdated
class Plug(Device):
"""Main class representing the smart wifi socket / plug."""

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

mirobo/plug.py Outdated

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

mirobo/plug.py Outdated
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?

mirobo/plug.py Outdated

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?

mirobo/plug.py Outdated
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

return self.data["current"]

def __str__(self) -> str:
s = "<PlugStatus power=%s, temperature=%s, current=%s>" % (self.state, self.temperature, 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 (110 > 79 characters)

return self.data["current"]

def __str__(self) -> str:
s = "<PlugStatus power=%s, temperature=%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 (85 > 79 characters)

@syssi
Copy link
Collaborator Author

syssi commented Jul 19, 2017

Looks good! Have you thought how this could look from the side of the console client?

I have no idea honestly. Just provide a second CLI called "plug"?

s = "<PlugStatus power=%s, " % (self.state)
s += "temperature=%s, " % (self.temperature)
s += "current=%s>" % (self.current)
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.

@rytilahti
Copy link
Owner

That, or using the same client but providing "methods" depending on the discovered device type, considering that there are quite a bit of devices which could be easily supported. I think this can be merged already now.

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


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)

import sys
import json
import ipaddress
from typing import Any

Choose a reason for hiding this comment

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

'typing.Any' imported but unused

import pretty_cron
import ast
import sys
import json

Choose a reason for hiding this comment

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

'json' imported but unused

# -*- coding: UTF-8 -*-
import logging
import click
import pretty_cron

Choose a reason for hiding this comment

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

'pretty_cron' imported but unused

@rytilahti
Copy link
Owner

Thanks, maybe in the future it makes sense to just extend one tool to cover all the devices, but the cli solution shall work for now :-)

@rytilahti rytilahti merged commit e1ab84c into rytilahti:master Jul 21, 2017
@syssi
Copy link
Collaborator Author

syssi commented Aug 3, 2017

$ .local/bin/mirobo --ip 192.168.130.57 --token b051cdxxxxxxxxxxxxxxxxxxxxxxxdb -d info
INFO:mirobo.vacuum_cli:Debug mode active
DEBUG:mirobo.vacuum_cli:Read stored sequence ids: {'seq': 7, 'manual_seq': 0}
DEBUG:mirobo.vacuum_cli:Connecting to 192.168.130.57 with token b051cdxxxxxxxxxxxxxxxxxxxxxxxdb
DEBUG:mirobo.protocol:Unable to decrypt, returning raw bytes.
DEBUG:mirobo.device:Discovered 843 14557 with ts: 1970-01-01 01:14:27
DEBUG:mirobo.device:192.168.130.57:54321 >>: {'id': 8, 'params': [], 'method': 'miIO.info'}
DEBUG:mirobo.device:192.168.130.57:54321 (ts: 1970-01-01 01:14:27, id: 8) << {'id': 8, 'result': {'life': 4467, 'hw_ver': 'MW300', 'netif': {'localIp': '192.168.130.57', 'mask': '255.255.255.0', 'gw': '192.168.130.1'}, 'model': 'chuangmi.plug.m1', 'cfg_time': 0, 'otu_stat': [303, 300, 12, 0, 12, 567], 'wifi_fw_ver': 'SD878x-14.76.36.p84-702.1.0-WM', 'ot': 'otu', 'token': 'b051cdxxxxxxxxxxxxxxxxxxxxxxxdb', 'fw_ver': '1.2.4_16', 'mac': '28:6C:FF:FF:FF:FF', 'ap': {'bssid': 'C0:25:06:A8:9A:5E', 'rssi': -69, 'ssid': 'Greendale'}, 'ott_stat': [0, 0, 0, 0], 'mmfree': 30296}}
chuangmi.plug.m1 v1.2.4_16 (28:6C:FF:FF:FF:FF) @ 192.168.130.57 - token: b051cdxxxxxxxxxxxxxxxxxxxxxxxdb
DEBUG:mirobo.vacuum_cli:Full response: {'ap': {'bssid': 'C0:25:06:A8:9A:5E', 'rssi': -69, 'ssid': 'Greendale'},
 'cfg_time': 0,
 'fw_ver': '1.2.4_16',
 'hw_ver': 'MW300',
 'life': 4467,
 'mac': '28:6C:FF:FF:FF:FF',
 'mmfree': 30296,
 'model': 'chuangmi.plug.m1',
 'netif': {'gw': '192.168.130.1',
           'localIp': '192.168.130.57',
           'mask': '255.255.255.0'},
 'ot': 'otu',
 'ott_stat': [0, 0, 0, 0],
 'otu_stat': [303, 300, 12, 0, 12, 567],
 'token': 'b051cdxxxxxxxxxxxxxxxxxxxxxxxdb',
 'wifi_fw_ver': 'SD878x-14.76.36.p84-702.1.0-WM'}
DEBUG:mirobo.vacuum_cli:Writing {'seq': 8, 'manual_seq': 0} to /tmp/python-mirobo.seq

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants