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

Support of the unified command line interface for all devices #289

Merged
merged 18 commits into from
Apr 8, 2018

Conversation

syssi
Copy link
Collaborator

@syssi syssi commented Mar 31, 2018

No description provided.

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

@command(
default_output = format_output("Powering off"),

Choose a reason for hiding this comment

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

unexpected spaces around keyword / parameter equals

@@ -146,34 +167,63 @@ def status(self) -> PowerStripStatus:
return PowerStripStatus(
defaultdict(lambda: None, zip(properties, values)))

@command(
default_output = format_output("Powering on"),

Choose a reason for hiding this comment

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

unexpected spaces around keyword / parameter equals

@command(
click.argument("brightness", type=int),
click.argument("cct", type=int),
default_output=format_output("Setting brightness to {brightness} and color temperature to {cct}")

Choose a reason for hiding this comment

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

line too long (105 > 100 characters)

def oscillate_off(self):
"""Disable oscillate."""
return self.send("set_angle_enable", ["off"])

@command(
click.argument("brightness", type=EnumType(LedBrightness, False)),

Choose a reason for hiding this comment

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

undefined name 'EnumType'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Import added.

def set_speed_level(self, level: int):
"""Set speed level."""
level = max(0, min(level, 100))
return self.send("set_speed_level", [level]) # 0...100

@command(
click.argument("direction", type=EnumType(MoveDirection, False)),

Choose a reason for hiding this comment

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

undefined name 'EnumType'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Import added.

miio/ceil.py Outdated
@command(
click.argument("brightness", type=int),
click.argument("cct", type=int),
default_output=format_output("Setting brightness to {brightness} and color temperature to {cct}")

Choose a reason for hiding this comment

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

line too long (105 > 100 characters)

@coveralls
Copy link

coveralls commented Mar 31, 2018

Coverage Status

Coverage increased (+0.4%) to 70.095% when pulling bb9302e on syssi:feature/unified-cli-support into 91b05a1 on rytilahti:master.

@syssi syssi assigned syssi and unassigned syssi Mar 31, 2018
@syssi syssi requested a review from rytilahti March 31, 2018 21:18
@syssi syssi force-pushed the feature/unified-cli-support branch from 17ac625 to f5547d7 Compare April 1, 2018 07:14
from .dummies import DummyDevice
import datetime
from miio import Vacuum, VacuumStatus, VacuumException

Choose a reason for hiding this comment

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

'miio.VacuumException' imported but unused

from .dummies import DummyDevice
import datetime
from miio import Vacuum, VacuumStatus, VacuumException

Choose a reason for hiding this comment

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

'miio.VacuumException' imported but unused

@@ -1,6 +1,9 @@
import logging
import warnings

import click

from .click_common import command, format_output, EnumType

Choose a reason for hiding this comment

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

'.click_common.EnumType' imported but unused

@syssi syssi changed the title Support of the unified commad line interface added to many devices Support of the unified command line interface for all devices Apr 3, 2018
@syssi syssi force-pushed the feature/unified-cli-support branch from fc92fde to c7939cd Compare April 4, 2018 06:24
@syssi
Copy link
Collaborator Author

syssi commented Apr 4, 2018

I would be happy to merge this soon. Rebasing the PR takes a lot of time.

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.

There is quite a bit to review, but I think we can simply merge this and do clean-ups later on. I just added a couple of comments for now.

@@ -19,4 +19,5 @@
from miio.wifirepeater import WifiRepeater
from miio.wifispeaker import WifiSpeaker
from miio.yeelight import Yeelight

Copy link
Owner

Choose a reason for hiding this comment

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

Remove the newline.

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 made this newline because miio.discovery cannot be moved to line 10. The position of this import is important. The newline shall help here. ;-)

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, I'm not following? Why it cannot be moved/why it is important?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I move the discovery import to the top the tests are failing:

_______________________________________________________________________________________ ERROR collecting miio/tests/test_airconditioningcompanion.py _________________________________________________________________________________________
ImportError while importing test module '/home/sebastian/src/python-miio/miio/tests/test_airconditioningcompanion.py'.                                                                                                                         
Hint: make sure your test modules/packages have valid Python names.                                                                                                                                                                            
Traceback:                                                                                                                                                                                                                                     
miio/__init__.py:2: in <module>                                                                                                                                                                                                                
    from miio.discovery import Discovery                                                                                                                                                                                                       
miio/discovery.py:10: in <module>                                                                                                                                                                                                              
    from . import (Device, Vacuum, ChuangmiPlug, PowerStrip, AirPurifier, Ceil,                                                                                                                                                                
E   ImportError: cannot import name 'Device'                                                                                                                                                                                                   
______________________________________________________________________________________________ ERROR collecting miio/tests/test_airhumidifier.py ______________________________________________________________________________________________
ImportError while importing test module '/home/sebastian/src/python-miio/miio/tests/test_airhumidifier.py'.                                                                                                                                    
Hint: make sure your test modules/packages have valid Python names.                                                                                                                                                                            
Traceback:                                                                                                                                                                                                                                     
miio/__init__.py:2: in <module>                                                                                                                                                                                                                
    from miio.discovery import Discovery                                                                                                                                                                                                       
miio/discovery.py:10: in <module>                                                                                                                                                                                                              
    from . import (Device, Vacuum, ChuangmiPlug, PowerStrip, AirPurifier, Ceil,                                                                                                                                                                
E   ImportError: cannot import name 'Device'

Copy link
Owner

Choose a reason for hiding this comment

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

Ohh, I see. I just didn't understand why the new line was necessary (as it should be just about the order, right?), but this is fine for me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct! :-)

def status(self) -> AirConditioningCompanionStatus:
"""Return device status."""
status = self.send("get_model_and_state", [])
return AirConditioningCompanionStatus(status)

@command(
default_output=format_output("Powering the air condition on"),
)
Copy link
Owner

Choose a reason for hiding this comment

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

When it all fits into one line (and there are no arguments), I think it'd be nice to have it all on a single line.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Are you sure? It feels hard to read because of the braces and the little spaces.

Copy link
Owner

Choose a reason for hiding this comment

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

Well, I think it would be nicer for grepping the code, but it's not so important and can be changed later if needed.

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 to me, I think we can merge and adjust as needed. What also needs to be added is an updated documentation for the new style cli before releasing a new version.


class AirConditioningCompanion(Device):
"""Main class representing Xiaomi Air Conditioning Companion."""

@command(
default_output=format_output(
"",
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe it would make sense to use a keyword argument here, otherwise it remains unclear what does "" do.

@syssi syssi merged commit 71195ce into rytilahti:master Apr 8, 2018
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.

4 participants