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

Added support for Xiaomi Philips Eyecare Smart Lamp 2 #34

Merged
merged 3 commits into from
Aug 14, 2017

Conversation

kuduka
Copy link
Contributor

@kuduka kuduka commented Jul 30, 2017

Added initial support for Xiaomi Philips Eyecare Smart Lamp 2

Usage: mieye [OPTIONS] COMMAND [ARGS]...

A tool to command Xiaomi Philips Eyecare Smart Lamp 2.

Options:
--ip TEXT
--token TEXT
-d, --debug
--help Show this message and exit.

Commands:
ambient_off Ambient Light off.
ambient_on Ambient Light on.
bl_off Night Light off.
bl_on Night Light on.
delay_off Set delay off in minutes.
discover Search for plugs in the network.
notify_off Eye Fatigue Reminder off.
notify_on Eye Fatigue Reminder On.
off Power off.
on Power on.
set_amb_bright Set Ambient Light brightness level.
set_bright Set brightness level.
set_scene Set eyecare scene number.
status Returns the state information.

"""Set Ambient Light brightness level."""
click.echo("Ambient Light Brightness: %s" % dev.set_amb_bright(level))

if __name__ == "__main__":

Choose a reason for hiding this comment

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

expected 2 blank lines after class or function definition, found 1

"""Ambient Light off."""
click.echo("Ambient Light Off: %s" % dev.amb_off())

@cli.command()

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

"""Ambient Light on."""
click.echo("Ambient Light On: %s" % dev.amb_on())

@cli.command()

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

"""Eye Fatigue Reminder off."""
click.echo("Eye Fatigue Reminder Off: %s" % dev.notify_user_off())

@cli.command()

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

"""Eye Fatigue Reminder On."""
click.echo("Eye Fatigue Reminder On: %s" % dev.notify_user_on())

@cli.command()

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

"""Power on."""
click.echo("Power on: %s" % dev.on())

@cli.command()

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

click.echo("Night Light: %s " % res.bls)
click.echo("Delay Off: %s minutes" % res.dvalue)

@cli.command()

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

"""Search for plugs in the network."""
mirobo.PhilipsEyecare.discover()

@cli.command()

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

if ctx.invoked_subcommand is None:
ctx.invoke(status)

@cli.command()

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

raise click.BadParameter('Should be a positive int between 1-3.')
return value

def validate_ip(ctx, param, value):

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

"""Set Ambient Light brightness level."""
click.echo("Ambient Light Brightness: %s" % dev.set_amb_bright(level))

if __name__ == "__main__":

Choose a reason for hiding this comment

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

expected 2 blank lines after class or function definition, found 1

"""Ambient Light off."""
click.echo("Ambient Light Off: %s" % dev.amb_off())

@cli.command()

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

"""Ambient Light on."""
click.echo("Ambient Light On: %s" % dev.amb_on())

@cli.command()

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

"""Eye Fatigue Reminder off."""
click.echo("Eye Fatigue Reminder Off: %s" % dev.notify_user_off())

@cli.command()

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

"""Eye Fatigue Reminder On."""
click.echo("Eye Fatigue Reminder On: %s" % dev.notify_user_on())

@cli.command()

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

"""Power on."""
click.echo("Power on: %s" % dev.on())

@cli.command()

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

click.echo("Night Light: %s " % res.bls)
click.echo("Delay Off: %s minutes" % res.dvalue)

@cli.command()

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

"""Search for plugs in the network."""
mirobo.PhilipsEyecare.discover()

@cli.command()

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

if ctx.invoked_subcommand is None:
ctx.invoke(status)

@cli.command()

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

raise click.BadParameter('Should be a positive int between 1-3.')
return value

def validate_ip(ctx, param, value):

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

_LOGGER = logging.getLogger(__name__)
pass_dev = click.make_pass_decorator(mirobo.PhilipsEyecare)

def validate_bright(ctx, param, value):

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

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

Choose a reason for hiding this comment

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

'ast' imported but unused

return self.data["dvalue"]


def __str__(self) -> str:

Choose a reason for hiding this comment

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

too many blank lines (2)

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

Choose a reason for hiding this comment

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

blank line contains whitespace

)
return PhilipsEyecareStatus(dict(zip(properties, values)))

class PhilipsEyecareStatus:

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

def status(self):
"""Retrieve properties."""
properties = ['power', 'bright', 'notifystatus',
'ambstatus', 'ambvalue', 'eyecare', 'scene_num',

Choose a reason for hiding this comment

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

continuation line under-indented for visual indent
trailing whitespace


def status(self):
"""Retrieve properties."""
properties = ['power', 'bright', 'notifystatus',

Choose a reason for hiding this comment

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

trailing whitespace

def set_user_scene(self, num: int):
"""Set eyecare user scene."""
return self.send("set_user_scene", [num])

Choose a reason for hiding this comment

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

blank line contains whitespace

from typing import Any, Dict
import enum

class PhilipsEyecare(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

@@ -0,0 +1,134 @@
from .device import Device
from typing import Any, Dict
import enum

Choose a reason for hiding this comment

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

'enum' imported but unused

@rytilahti
Copy link
Owner

Could you please run mirobo -d info on the current master and provide the printed out model?

@kuduka
Copy link
Contributor Author

kuduka commented Aug 1, 2017

Device ID is the same one as in this PR, although no idea what is that 55249:

0x02f9: "Xiaomi Philips Eyecare Smart Lamp 2

With this lamp mirobo crashes as it doesn't have get_status method:

(venv) [kuduk@xps13 python-mirobo]$ venv/bin/mirobo --ip 192.168.1.191 --token xxx -d 
INFO:mirobo.vacuum_cli:Debug mode active
ERROR:mirobo.vacuum_cli:Unable to read the stored msgid: [Errno 2] No such file or directory: '/tmp/python-mirobo.seq'
DEBUG:mirobo.vacuum_cli:Connecting to 192.168.1.191 with token d177973a1fa6262b0831792aad342fad
DEBUG:mirobo.protocol:Unable to decrypt, returning raw bytes.
DEBUG:mirobo.device:Discovered 761 55249 with ts: 1970-01-01 00:10:19
DEBUG:mirobo.device:192.168.1.191:54321 >>: {'id': 1, 'method': 'get_status'}
DEBUG:mirobo.device:192.168.1.191:54321 (ts: 1970-01-01 00:10:19, id: 1) << {'id': 1, 'error': {'code': -32600, 'message': 'Req object invalid.'}}
Traceback (most recent call last):

@rytilahti
Copy link
Owner

That's discovery, I mean you have to try mirobo -d info, it will show something similar to this:
rockrobo.vacuum.v1 v3.3.9_003077 (28:6C:07:XX:XX:XX) @ 192.168.XXX.XXX - token: 476e6b70343055483XXXXXXXXXXXXX. The first part is the model name, the second one the FW version etc. With -d you will see the whole response though, maybe there is also some other interesting parts so it's worth checking out.

@kuduka
Copy link
Contributor Author

kuduka commented Aug 1, 2017

I just saw my mistake, here's the good one, sorry for the confusion!


(venv) [kuduk@xps13 python-mirobo]$ venv/bin/mirobo --ip 192.168.1.191 --token d177973a1fa6262b0831792aad342fad -d info
INFO:mirobo.vacuum_cli:Debug mode active
<_io.TextIOWrapper name='/tmp/python-mirobo.seq' mode='r' encoding='UTF-8'>
DEBUG:mirobo.vacuum_cli:Read stored sequence ids: {'seq': 1, 'manual_seq': 0}
DEBUG:mirobo.vacuum_cli:Connecting to 192.168.1.191 with token d177973a1fa6262b0831792aad342fad
DEBUG:mirobo.protocol:Unable to decrypt, returning raw bytes.
DEBUG:mirobo.device:Discovered 761 55249 with ts: 1970-01-01 00:00:07
DEBUG:mirobo.device:192.168.1.191:54321 >>: {'id': 2, 'method': 'miIO.info', 'params': []}
DEBUG:mirobo.device:192.168.1.191:54321 (ts: 1970-01-01 00:00:07, id: 2) << {'result': {'life': 7, 'token': 'd177973a1fa6262b0831792aad342fad', 'mac': '28:6C:07:2A:9B:BC', 'fw_ver': '1.2.8', 'hw_ver': 'ESP8266', 'model': 'philips.light.sread1', 'mcu_fw_ver': '0024', 'wifi_fw_ver': '1.4.0(30e0bd0)', 'ap': {'rssi': -69, 'ssid': 'XarxaCasa', 'bssid': '5C:35:3B:EA:97:DE'}, 'netif': {'localIp': '192.168.1.191', 'mask': '255.255.255.0', 'gw': '192.168.1.1'}, 'mmfree': 11720}, 'id': 2}
philips.light.sread1 v1.2.8 (28:6C:07:2A:9B:BC) @ 192.168.1.191 - token: d177973a1fa6262b0831792aad342fad
DEBUG:mirobo.vacuum_cli:Full response: {'ap': {'bssid': '5C:35:3B:EA:97:DE', 'rssi': -69, 'ssid': 'XarxaCasa'},
 'fw_ver': '1.2.8',
 'hw_ver': 'ESP8266',
 'life': 7,
 'mac': '28:6C:07:2A:9B:BC',
 'mcu_fw_ver': '0024',
 'mmfree': 11720,
 'model': 'philips.light.sread1',
 'netif': {'gw': '192.168.1.1',
           'localIp': '192.168.1.191',
           'mask': '255.255.255.0'},
 'token': 'd177973a1fa6262b0831792aad342fad',
 'wifi_fw_ver': '1.4.0(30e0bd0)'}
DEBUG:mirobo.vacuum_cli:Writing {'seq': 2, 'manual_seq': 0} to /tmp/python-mirobo.seq

@rytilahti
Copy link
Owner

Thanks, that's looking good! Interesting that it sports ESP8266 (hw_ver) :-) I think this can actually be merged now, it just needs some refactoring after refactoring the client tool to behave nicer.

syssi added a commit to syssi/python-miio that referenced this pull request Aug 14, 2017
@rytilahti
Copy link
Owner

rytilahti commented Aug 14, 2017

As the necessary information for refactoring the client tool is either here or in the source code, let's merge this as I'm unsure when I get some time to look into refactoring the tool. Thanks a lot for the PR 👍

@rytilahti rytilahti merged commit 3b886ad into rytilahti:master Aug 14, 2017
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