-
-
Notifications
You must be signed in to change notification settings - Fork 221
Add DeviceConfig to allow specifying configuration parameters #569
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
Conversation
b5bdc41
to
f1237b4
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #569 +/- ##
==========================================
+ Coverage 84.83% 85.01% +0.17%
==========================================
Files 37 38 +1
Lines 3231 3389 +158
Branches 810 851 +41
==========================================
+ Hits 2741 2881 +140
- Misses 413 422 +9
- Partials 77 86 +9 ☔ View full report in Codecov by Sentry. |
I think this is fine, we can use the internal one to match the interfaces in the future. |
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 fine to me on the surface but I'll give it a try later. @bdraco do you see any concerns on this wrt homeassistant support?
Do you have a homeassistant branch (or alternatively, modifications to cli.py
) that is already using this? If yes, would you mind linking that to make testing this easier :-)
I have a homeassistant branch locally that incorporates @bdraco's home-assistant/core#104213 along with the connection_params and authorisation data flows. I need to finalise it tomorrow morning and then I'll create a PR and link it here. W.r.t |
Great. Can you send a PR to my HA core branch? I'll merge it in and test |
To the |
It makes sense to have them as separate options to avoid manually building json objects which can be a hassle. I hope having those parametrized will make it easier for someone to start looking into #422 and #467 using the |
0735690
to
71a4986
Compare
HA PRs are ready. This is still work in progress from a testing point of view but feedback welcome. @bdraco it would be good if you can put any comments on home-assistant/core#105143 so they're all in the same place. home-assistant/core#105144 for @bdraco home-assistant/core#105143 for @rytilahti and @ezekieldas @ezekieldas the way I usually test HA core changes is:
To checkout PRs (
EDIT @ezekieldas I've updated step 7 (now 8) to only skip installing the python-kasa package. This will be needed for when I rebase to |
FYI I have added optional functionality for In order to be able to do this without circular references the three |
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 tested this PR and the homeassistant counterpart and it's starting to look great! I wrote my end user experience in home-assistant/core#105143 (comment) so I won't repeat that feedback here.
So I skimmed over some of this PR (it's quite a lot of changes already.. :-D) and wanted to give some early feedback and potential ideas for improvements, much of this is rather abstract but I think we are in a position where we need to discuss about the mechanics to avoid issues down the path when it's more complicated to avoid breaking things.
Basically, what I have in my mind is that we need to thinkg about defining some "basic device types" (plugs, bulbs, dimmers, powerstrisp) which implement their corresponding interfaces. Any additional information and features would be implemented in an abstracted way by adding some metadata to implementations that lets us to find out and access features without hardcoding them.
I suppose this comment and the inline review comments serve as a sort of call for discussions on this matter :-)
Apologies things grew a bit to get it working properly with HA. With regard to breaking things I think in the short term we want to be able to change the So far HA is not really aware of the
One of the things with the SMART protocol is there is minimal information in the discovery response to determine the "basic device types", i.e. we only have the tplink device type of "SMART.BLAH" which may end up only having the same 2 types as IOT, i.e. bulb or plugswitch. We might want to keep the number of basic types in line with tplink and add |
I had some trouble with this but eventually got everything sorted out (see further below). Most important to note, and was the case with previous tests, is I had to set env Anyhow, this is the end result and it's fantastic! Issues:
|
71a4986
to
fed4237
Compare
Great to hear it's working for you @ezekieldas. I have updated both PRs to fix some useability and architectural issues. If you do check them both out again you should make sure to see my update to the instructions above to use Thanks for taking the time! |
fed4237
to
45aeef5
Compare
45aeef5
to
a21985e
Compare
FYI I have rebased this PR on top of a new PR #578 to use the tapo error_codes to determine whether to retry or fail etc. @rytilahti it would probably make sense to look at #578 first as it's fairly simple and will probably help you with your own testing. |
HA nor any other downstream should never be aware of our internals :-)
I'll try to go through this PR directly after the error code PR is merged and this is rebased on top of the master branch. But yeah, the only interface HA should be aware of (in my opinion) is that there's a way to get "connection parameters" out from an existing instance and constructing a device instance again by simply using that data.
Yup, and this is looking really good based on my testing with this PR and the one for HA already :-)
We don't want any mentions about such low-level things, this is all purely something that just magically happens in the background and should not matter to users: the integration will just suddenly start providing support for more devices (in exchange for creds) and that's about it.
The |
a21985e
to
bcf89de
Compare
#578 (comment) - Do you see this as a new optional parameter on
error_core PR now rebased into this PR. I'll look at removing The multi-request PR is nearly ready to submit once we're done with this one (I think you'll like it as it includes the query_helper type behaviour you requested). After that we do the feature interface PR and I reckon we're nearly there for the next release version and the HA PR :-O |
ad73e58
to
05bad39
Compare
Now rebased on top of #584 so in theory ready to go :D |
05bad39
to
ce7a89b
Compare
Hi @rytilahti, I've held off on submitting any more PRs so we can hopefully focus on finishing this one off before the holidays. In the meantime I've managed to get hold of a L510 and prevent it updating so I have an AES device again. Also I've managed to get this dynamic_light_effect update working locally so just in case you were going to spend time on it I can share the solution. |
Hi @sdb9696 and happy holidays, feel free to create new PRs as you see fit. I've already traveled for the holidays and I may or may not have some free cycles in between to do some brief reviews :-)
Great, thanks for the notice 👍 feel free to create a PR for that, I'm rather unlikely to have spare cycles to do any coding at the moment but I can sneak in a review or two now and then. |
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 didn't go through all of it yet, but I'm feeling positive how it's turning out API-wise with the new config class 😀 I'm on mobile right now, but if there are ctors taking in port as an argument, we should remove those in favour of the config.
That's done now for all the |
d931ed4
to
8b940f2
Compare
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.
Sorry for the delay @sdb9696, the holiday time has been quite busy this year... So, just a couple of nits and suggestions, I'll give it a quick test later tonight, and I hope we can merge this and make further adjustments in separate, smaller PRs as necessary.
kasa/protocolfactory.py
Outdated
def get_protocol( | ||
cparams: ConnectionParameters, | ||
) -> Optional[TPLinkProtocol]: |
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'm currently rather busy to look it up, but couldn't we make the imports inside the function to avoid the circular deps?
Most of the suggestions now implemented. A couple of open questions with replies which we can hopefully discuss post-merge. One below I couldn't reply to directly:
Yes that's now done |
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.
LGTM, this is a great cleanup, thanks! 💯
I'm wondering if we should keep some of the existing parameters in the constructors but rather deprecate them for a release or two, but that's something which can be done in a separate PR if we feel that's worth having..
So, juts a couple of things to do and then this is ready to go:
- Please update the PR description with a "Breaking change" block to help writing the release notes & help someone coming in to look why their code broke and how to fix it.
- Update the documentation on initialization https://python-kasa.readthedocs.io/en/latest/design.html#initialization (and potentially, add a new section about describing the DeviceConfig).
1fb565b
to
9325ba5
Compare
Done.
Done. I'd like to spend a bit more time on the docs after this is merged but I think we have enough for now. |
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, let's get it merged then!
Breaking change
timeout
has been renamed todiscovery_timeout
astimeout
is now used to set the timeout for device communications on created instances.__init__
does not allowport
anymore, if you need to use custom port, you can construct aDeviceConfig
to do that.This PR replacing individual configuration parameters such as host, port, timeout etc with a
DeviceConfig
parameter which contains the underlying configuration parameters. For consumers who find this breaks their existing implementations simply import the newDeviceConfig
class and set the parameters on the configuration class and pass that into the device constructors or the theSmartDevice.connect()
factory method.The
DeviceConfig
class also enables support for connecting to new KASA SMART protocol and TAPO directly viaSmartDevice.connect()
without having to use discovery first. Simply serialize theSmartDevice.config
property withto_dict()
and then deserialize it later withDeviceConfig.from_dict()
and then pass it intoSmartDevice.connect()
.