-
-
Notifications
You must be signed in to change notification settings - Fork 566
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
Merge of the Chuangmi Plug V1, V2, V3 and M1 #270
Merge of the Chuangmi Plug V1, V2, V3 and M1 #270
Conversation
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 like the diffs which remove more than they add, well done! I added a couple of comments inline.
miio/device.py
Outdated
@@ -115,7 +115,7 @@ class Device: | |||
This class should not be initialized directly but a device-specific class inheriting | |||
it should be used instead of it.""" | |||
def __init__(self, ip: str = None, token: str = None, | |||
start_id: int=0, debug: int=0, lazy_discover: bool=True) -> None: | |||
start_id: int=0, debug: int=0, lazy_discover: bool=True, model: str=None) -> None: |
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.
Is it truly necessary to introduce this also on the parent level, or would it be fine to have it just in the subclass?
miio/discovery.py
Outdated
"chuangmi-plug-v3": PlugV3, | ||
"chuangmi-plug-v1": ChuangmiPlug, | ||
"chuangmi-plug_": ChuangmiPlug, | ||
"chuangmi-plug-v3": ChuangmiPlug, |
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.
For passing a parameter here you can use functools.partial
, so something like:
partial(ChuangmiPlug, model=MyModel)
can be used in this case.
I'm wondering whether that should be an enum, or simply an integer model_version
, which would default to either of them? We could also derive the model (if not given) per default from the status information (to adapt the setters accordingly), as it's just one extra attribute & different naming?
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 will care about tomorrow.
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.
The check_and_create_device
method doesn't enter the inspect.isclass(v)
branch anymore if I use a partial. I'm unsure about a good implementation.
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.
Indeed.. Hmm, maybe adding a check if it's partial and extracting the class out from it?
>>> from functools import partial
>>> class A:
>>> pass
>>> partial(A, foo=1).func
<class '__main__.A'>
edit: that does interfere with the iscallable check.. It shouldn't be a problem though, when the check order is:
- Is a class
- Is a partial, containing a class
- Is callable
miio/__init__.py
Outdated
@@ -1,11 +1,10 @@ | |||
# flake8: noqa | |||
from miio.protocol import Message, Utils | |||
from miio.vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus, | |||
CleaningDetails, CleaningSummary, Timer) | |||
CleaningDetails, CleaningSummary, Timer, ) |
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.
Is this a necessary change?
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.
No. :-)
miio/chuangmi_plug.py
Outdated
MODEL_CHUANGMI_PLUG_M1: ['power', 'temperature'] | ||
} | ||
|
||
class ChuangmiPlugStatus: |
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.
expected 2 blank lines, found 1
miio/device.py
Outdated
@@ -131,6 +131,7 @@ def __init__(self, ip: str = None, token: str = None, | |||
self.token = bytes.fromhex(token) | |||
self.debug = debug | |||
self.lazy_discover = lazy_discover | |||
self.model = model |
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 'model'
One open question is whether we want to keep backwards compatibility with the old class naming? If yes, that could be simply done by creating small wrapper classes located inside |
Could you review the changes? I don't know how to improve the tests. The constructor of the old classes should be called and the base class must be mocked somehow. |
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.
A couple of minor improvement ideas. After those are changed let's get this merged, the tests can be improved at some later point.
miio/__init__.py
Outdated
from miio.chuangmi_plug import Plug | ||
from miio.chuangmi_plug import PlugV1 | ||
from miio.chuangmi_plug import PlugV3 | ||
from miio.chuangmi_plug import ChuangmiPlug |
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.
from miio.chuangmi_plug import (Plug, PlugV1, PlugV3, ChuangiPlug)
would be nicer here.
miio/chuangmi_plug.py
Outdated
model=model) | ||
|
||
|
||
class Plug(ClassDeprecatedPlug): |
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 created PR #276 to move the deprecated decorator out from vacuumcontainers, it should be used to decorate these classes to inform anyone trying to initialize these classes.
Comma removed.
This reverts commit 7eb1443.
3ccef7e
to
200a738
Compare
Done :-) |
miio/chuangmi_plug.py
Outdated
@@ -0,0 +1,181 @@ | |||
import logging | |||
import warnings |
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.
'warnings' imported but unused
remvoe unused warnings.
Great, thanks! 💯 |
@rytilahti Could you provide a recommendation for the "device model enum" and the discovery device map?