8000 Tplink klap protocol by sdb9696 · Pull Request #100356 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Tplink klap protocol #100356

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

Closed
wants to merge 2 commits into from
Closed

Conversation

sdb9696
Copy link
Contributor
@sdb9696 sdb9696 commented Sep 14, 2023

Breaking change

Proposed change

Update tplink integration to work with kasa klap protocol. Currently in draft as python-kasa needs to be released to support it and there's a conversation to be had with @rytilahti about the implementation.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

Hi @sdb9696

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@home-assistant
Copy link

Hey there @rytilahti, @TheGardenMonkey, mind taking a look at this pull request as it has been labeled with an integration (tplink) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of tplink can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign tplink Removes the current integration label and assignees on the pull request, add the integration domain after the command.

@sdb9696
Copy link
Contributor Author
sdb9696 commented Sep 14, 2023

@rytilahti 12 hours ago
It would be easier to just update them all without checking if a change is needed, given the syncing is enabled.

As it happens the updated event only fires if the value changes but I was concerned that if the update event implementation ever changed and ended up firing whenever update is called then this would cause a big problem. They'd all keep updating and raising the events on the other config entries infinitely.

@rytilahti 12 hours ago
As this is a config entry specific setting, I have my doubts if it would be acceptable for homeassistant inclusion. How about doing it like this instead of syncing:

If the device works as-is, nothing to do
If the auth exception gets raised, ask user to input the creds
On success, store inside self.hass[DOMAIN] and trigger reauth on other devices with the same error
This way, the creds are 1) stored in the config entry per-device basis, 2) there is no need for special syncing option, and 3) the >user needs to supply the correct creds only once per session.

What do you think?

Having to re-enter them on restart would be quite annoying. I initially implemented a global approach here that also handled the persistent storage but it was a bit ugly. There seems to be two paradigms for integrations using config flow, one where the whole integration has a single config entry (and all devices will be added like ring) and it's easy to configure options for the integration, and the other (i.e. tplink) where a config entry is created per device (more control for the user) but then integration level options don't seem to have support in HA.

Having implemented both the global storage approach and the options approach, the user experience with the OptionsFlow is much better and it's more obvious to the user how to fix it as they just click configure. Maybe we could ask this question to some of the HA architects to get a view?

@rytilahti 12 hours ago
Not worth separate encryption here as such information is usually stored unencrypted on the disk anyway in homeassistant.

I saw a bunch of people complaining on reddit about passwords being stored by HA in plain text and there was a question raised to discuss it. I figured that as we have an encryption library to hand there was no harm but happy to remove.

@rytilahti
Copy link
Member

As it happens the updated event only fires if the value changes but I was concerned that if the update event implementation ever changed and ended up firing whenever update is called then this would cause a big problem. They'd all keep updating and raising the events on the other config entries infinitely.

Is it possible to withdraw the auth error, i.e., retriggering the flow after the creds have been inputted once? This way, the flow could could save the creds under self.hass[DOMAIN][something] to be re-used automatically to discard other errors if the credentials worked.

Having to re-enter them on restart would be quite annoying. I initially implemented a global approach here that also handled the persistent storage but it was a bit ugly. There seems to be two paradigms for integrations using config flow, one where the whole integration has a single config entry (and all devices will be added like ring) and it's easy to configure options for the integration, and the other (i.e. tplink) where a config entry is created per device (more control for the user) but then integration level options don't seem to have support in HA.

So I think there are two cases:

  1. When the correct credentials are stored in the config entry, there's nothing to input
  2. If authentication is needed, we can store the newly inputted creds not only in the config entry but also inside self.hass[DOMAIN] to make them available for other config flow instances.

Am I missing something?

While not optimal when adding new devices, this would require user to input the credentials only once even if they are adding several devices, right? I suppose the proper way would be to have an "integration store" where we could read this, but I'm not sure if such exists at the moment.

Having implemented both the global storage approach and the options approach, the user experience with the OptionsFlow is much better and it's more obvious to the user how to fix it as they just click configure. Maybe we could ask this question to some of the HA architects to get a view?

Yeah, I have heard about different approaches but never really looked into that. I agree that it'd be helpful if someone with more knowledge would chime in what's the best approach here.

I saw a bunch of people complaining on reddit about passwords being stored by HA in plain text and there was a question raised to discuss it. I figured that as we have an encryption library to hand there was no harm but happy to remove.

We want to keep the integration as simple as possible. If encryption is wanted, it should be done by homeassistant core. I did not know about the store, what were the problems when using it for storing information?

@rytilahti
Copy link
Member

@sdb9696 this has been made obsolete by #105143 and should be closed, right?

@sdb9696 sdb9696 closed this Dec 31, 2023
@sdb9696
Copy link
Contributor Author
sdb9696 commented Dec 31, 2023

Done

@github-actions github-actions bot locked and limited conversation to collaborators Jan 1, 2024
@sdb9696 sdb9696 deleted the tplink_klap_protocol branch April 4, 2024 13:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0