Merge of the Chuangmi Plug V1, V2, V3 and M1#270
Merge of the Chuangmi Plug V1, V2, V3 and M1#270rytilahti merged 19 commits intorytilahti:masterfrom
Conversation
rytilahti
left a comment
There was a problem hiding this comment.
I like the diffs which remove more than they add, well done! I added a couple of comments inline.
miio/device.py
Outdated
| 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.
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.
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.
I will care about tomorrow.
There was a problem hiding this comment.
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.
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
| from miio.protocol import Message, Utils | ||
| from miio.vacuumcontainers import (VacuumStatus, ConsumableStatus, DNDStatus, | ||
| CleaningDetails, CleaningSummary, Timer) | ||
| CleaningDetails, CleaningSummary, Timer, ) |
| MODEL_CHUANGMI_PLUG_M1: ['power', 'temperature'] | ||
| } | ||
|
|
||
| class ChuangmiPlugStatus: |
miio/device.py
Outdated
| self.token = bytes.fromhex(token) | ||
| self.debug = debug | ||
| self.lazy_discover = lazy_discover | ||
| self.model = 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. |
rytilahti
left a comment
There was a problem hiding this comment.
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.
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.
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 | |||
remvoe unused warnings.
|
Great, thanks! 💯 |
@rytilahti Could you provide a recommendation for the "device model enum" and the discovery device map?