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

Merge of the Chuangmi Plug V1, V2, V3 and M1 #270

Merged
merged 19 commits into from
Mar 26, 2018

Conversation

syssi
Copy link
Collaborator

@syssi syssi commented Mar 16, 2018

@rytilahti Could you provide a recommendation for the "device model enum" and the discovery device map?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 69.043% when pulling b2e3965 on syssi:feature/marriage-chuangmi-v1-and-v3 into 17e8e69 on rytilahti:master.

@coveralls
Copy link

coveralls commented Mar 16, 2018

Coverage Status

Coverage decreased (-0.4%) to 68.847% when pulling 7685d79 on syssi:feature/marriage-chuangmi-v1-and-v3 into 020b861 on rytilahti:master.

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.

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:
Copy link
Owner

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?

"chuangmi-plug-v3": PlugV3,
"chuangmi-plug-v1": ChuangmiPlug,
"chuangmi-plug_": ChuangmiPlug,
"chuangmi-plug-v3": ChuangmiPlug,
Copy link
Owner

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?

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 will care about tomorrow.

Copy link
Collaborator Author

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.

Copy link
Owner

@rytilahti rytilahti Mar 17, 2018

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:

  1. Is a class
  2. Is a partial, containing a class
  3. 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, )
Copy link
Owner

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No. :-)

MODEL_CHUANGMI_PLUG_M1: ['power', 'temperature']
}

class ChuangmiPlugStatus:

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

Choose a reason for hiding this comment

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

undefined name 'model'

@syssi syssi changed the title Merge of the Chuangmi Plug V1 and V3 Merge of the Chuangmi Plug V1, V2, V3 and M1 Mar 16, 2018
@rytilahti
Copy link
Owner

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 chuangmi_plug, which are also exported (and yielding a warning about deprecation).

@syssi
Copy link
Collaborator Author

syssi commented Mar 24, 2018

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.

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.

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
Copy link
Owner

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.

model=model)


class Plug(ClassDeprecatedPlug):
Copy link
Owner

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.

@syssi syssi force-pushed the feature/marriage-chuangmi-v1-and-v3 branch from 3ccef7e to 200a738 Compare March 26, 2018 11:47
@syssi
Copy link
Collaborator Author

syssi commented Mar 26, 2018

Done :-)

@@ -0,0 +1,181 @@
import logging
import warnings

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.
@rytilahti
Copy link
Owner

Great, thanks! 💯

@rytilahti rytilahti merged commit 42e6035 into rytilahti:master Mar 26, 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