Skip to content

Re-add protocol_class parameter to connect #551

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

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

sdb9696
Copy link
Collaborator

@sdb9696 sdb9696 commented Nov 22, 2023

It seems the move of connect() out of discovery dropped the protocol_class parameter needed to create devices with different protocols. I've re-added it pretty much as per before.

Copy link

codecov bot commented Nov 22, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d3c2861) 82.24% compared to head (d0e4cc5) 82.27%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #551      +/-   ##
==========================================
+ Coverage   82.24%   82.27%   +0.03%     
==========================================
  Files          30       30              
  Lines        2461     2466       +5     
  Branches      692      694       +2     
==========================================
+ Hits         2024     2029       +5     
  Misses        379      379              
  Partials       58       58              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@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.

LGTM, thanks 👍

@sdb9696
Copy link
Collaborator Author

sdb9696 commented Nov 22, 2023

Hi, could you merge this please @rytilahti? Are you going to publish a release soon?

Copy link
Member

@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.

So I didn't want to rush on merging this to give some time for second thoughts.. Which led me to think that it might be a good idea for potential extensibility to create an enum instead of using a directly class type for defining the wanted protocol. I'm not yet completely sure about what's the best approach, but I think it makes sense to try to relieve downstreams from importing internal classes (like the protocol ones) if this library extends to cover other transport protocols like for those cams and tapo devices.

About the new release, I might be able to squeeze a release out on the weekend but I can't make promises due to some upcoming deadlines.

@sdb9696
Copy link
Collaborator Author

sdb9696 commented Nov 23, 2023

Ok fair enough. I was thinking about how this would be stored in and re-used in HA. As it seems to be the discovery info that determines the protocol, one approach could be to create a protocol factory (either in it's own module or as part of the discovery module). This could take a parameter of the pydantic DiscoveryResult we created which can then be serialized and stored in HA. Similar to the storing of the DeviceType this could then be used to pass the protocol class to connect()

What do you think? ping @bdraco, for context here it seems that some kasa EP25 devices are starting to use the TAPO protocol

@bdraco
Copy link
Member

bdraco commented Nov 23, 2023

Ok fair enough. I was thinking about how this would be stored in and re-used in HA. As it seems to be the discovery info that determines the protocol, one approach could be to create a protocol factory (either in it's own module or as part of the discovery module). This could take a parameter of the pydantic DiscoveryResult we created which can then be serialized and stored in HA. Similar to the storing of the DeviceType this could then be used to pass the protocol class to connect()

What do you think? ping @bdraco, for context here it seems that some kasa EP25 devices are starting to use the TAPO protocol

I think its a good idea to store the discovery results in some way in HA so we can reconnect easily, but I would be very nervous about relying on pydantic to do the serialization / deserialization as I've had so many problems with pydantic changes and breakage that I no longer use it in new code.

A simple data structure that is JSON serializable would probably be the best as it would make it easy to work for most systems and HA

@sdb9696
Copy link
Collaborator Author

sdb9696 commented Nov 28, 2023

Hi @rytilahti, any further thoughts on whether we can merge this yet? I think we’re going to need it for the Klap HA PR to work after @bdraco moves the integration to use connect().

@rytilahti
Copy link
Member

This looks good to me and worth merging.

My only worry is that adding such "low-level" things (like importing custom protocols / initializing them) may not be acceptable for homeassistant..

So I was thinking, maybe we could create a very simple container for all necessary connection parameters (ConnectionParameters or something like that?), and make it possible to pass only that for constructing instances. W/o pydantic if that's a deal breaker, although I doubt it should be a problem in a non-nested model).

As long as we keep this backwards compatible, we can easily extend it without needing to touch homeassistant code. Basically, SmartDevice should be able to output this json serializable object, like @bdraco mentioned, as well as accept it to re-create the instance.

What we basically need is the following information to construct a device from zero, right?

  • Host
  • Port
  • Device type
  • Protocol (legacy, klap, aes)?
  • Username (if applicable)
  • Password (if applicable)
  • Timeout

What do you think?

@rytilahti rytilahti added the enhancement New feature or request label Nov 28, 2023
@rytilahti rytilahti merged commit 9728866 into python-kasa:master Nov 28, 2023
@sdb9696 sdb9696 deleted the add_protocol_to_connect branch December 6, 2023 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants