-
-
Notifications
You must be signed in to change notification settings - Fork 570
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
Conversation
miio/powerstrip.py
Outdated
def on(self): | ||
"""Power on.""" | ||
return self.send("set_power", ["on"]) | ||
|
||
@command( | ||
default_output = format_output("Powering off"), |
There was a problem hiding this comment.
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
miio/powerstrip.py
Outdated
@@ -146,34 +167,63 @@ def status(self) -> PowerStripStatus: | |||
return PowerStripStatus( | |||
defaultdict(lambda: None, zip(properties, values))) | |||
|
|||
@command( | |||
default_output = format_output("Powering on"), |
There was a problem hiding this comment.
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
miio/philips_bulb.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}") |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'EnumType'
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undefined name 'EnumType'
There was a problem hiding this comment.
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}") |
There was a problem hiding this comment.
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)
17ac625
to
f5547d7
Compare
miio/tests/test_vacuum.py
Outdated
from .dummies import DummyDevice | ||
import datetime | ||
from miio import Vacuum, VacuumStatus, VacuumException |
There was a problem hiding this comment.
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
miio/tests/test_vacuum.py
Outdated
from .dummies import DummyDevice | ||
import datetime | ||
from miio import Vacuum, VacuumStatus, VacuumException |
There was a problem hiding this comment.
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
miio/wifispeaker.py
Outdated
@@ -1,6 +1,9 @@ | |||
import logging | |||
import warnings | |||
|
|||
import click | |||
|
|||
from .click_common import command, format_output, EnumType |
There was a problem hiding this comment.
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
This reverts commit 91dc4d7.
fc92fde
to
c7939cd
Compare
I would be happy to merge this soon. Rebasing the PR takes a lot of time. |
There was a problem hiding this 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 | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the newline.
There was a problem hiding this comment.
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. ;-)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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'
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"), | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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( | ||
"", |
There was a problem hiding this comment.
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.
No description provided.