-
-
Notifications
You must be signed in to change notification settings - Fork 563
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
restructure and improve gateway subdevices #700
Conversation
Does it work with CLI? |
Too dirty but works
|
Same applies to all classes using the @command decorator. |
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.
Thanks for the PR with many great improvements and cleanups! There are some issues that needs to be solved before proceeding, see the first round of comments inline.
@bskaplou I only work with python3, I know almost nothing about the cli implementation, so honestly I have no idea if it works with cli, probably not yet... |
@bskaplou could you test using python3? In python3 this schould work: from miio import (gateway) Now select the sub device you want to control, for instance the first discovered device: Aqara1 = devices[0] |
@starkillerOG Yep it works... But CLI is important because it allows to play with lib and it's well documented... Right now CLI doesn't work because click is trying to create object with ip/token/etc passed to init you can resurrect CLI by adding following method to each subdevice
Click will call this init with cli arguments and everything works well |
This will probably work, but if I understand correctly this will create a new device including connection, handshake etc, for each feature of the Gateway + for each subdevice. That seems to be very dirty and will probably give us lots of trouble in the future. I know almost nothing about the cli and don't use it..... @bskaplou could you try to figure out a way that works with the cli but only uses one instance of the device class that is beeing re-used to only have one connection and handshake etc? |
Co-authored-by: Teemu R. <tpr@iki.fi>
Btw, if you are developing locally, the simplest way to make sure the checks are passing is to execute |
@rytilahti thanks for the tox -e lint hint, however I get a gazillion errors mostly about the doc files ending with .rst |
Can you paste an error or two? But looks like it's now passing, the only problem is that python3.6 does not support dataclasses, it seems... Please add dataclasses to the required packages (either by manually modifying pyproject.toml, or simply commanding I think we are bound to have that until homeassistant drops python 3.6 support.. |
@rytilahti do you know how to fix the tests failing? |
|
Please commit the |
running poetry add dataclasses
I think we have a problem.... |
Ah, after reading this python-poetry/poetry#1413 (comment) the simplest fix is to modify the required python version... So please replace this:
with
|
nope does not work:
|
Argh, okay.. Well, I think it's better get rid of The conversion is pretty simple:
The good thing with this is also (which I think we should have converted them anyway, at some point) that this will allow use converters (maybe we want to convert, e.g., the open/close or on/off to booleans)? |
@rytilahti I think I found a solution |
@starkillerOG ah, I saw the commit. Could you still do the attrs conversion, or should I do that? It's better in the long run to make it properly anyway.. |
Not today, I am going to bed, but I will do the conversion tommorow, or you can merge it now and do the conversion... |
Okay, no need to hurry with that, let's merge it then tomorrow (or whenever you find time to do that). Thanks for the great work already! 🥇 |
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.
Time to merge 💯
Thanks for all your help @rytilahti |
* restructure and improve gateway subdevices * Update gateway.py * fix cli * black formatting * filter out gateway * better error handeling * common GatewayDevice class for __init__ * remove duplicate "gateway" from method name * use device_type instead of device_name for mapping * add comments * use DeviceType.Gateway Co-authored-by: Teemu R. <tpr@iki.fi> * Update gateway.py * improve discovered info * fix formatting * better use of dev_info * final black formatting * process revieuw * generilize properties of subdevices * Subdevice schould not derive from Device * simplify dataclass props for subdevices * optimization * remove empty checks and futher simplify dataclass * Update gateway.py * add back SensorHT * add back Empty response * black formatting * add missing docstrings * fix except * fix black * Update pyproject.toml * Update pyproject.toml * fix dataclasses * replace dataclasses by attr * add get_local_status command * remove local.status again Co-authored-by: Teemu R. <tpr@iki.fi>
Restructure and improve gateway subdevices