Skip to content

Add exception for unsupported provisioning methods#1586

Open
rytilahti wants to merge 5 commits into
python-kasa:masterfrom
rytilahti:fix/specific_tss_exception
Open

Add exception for unsupported provisioning methods#1586
rytilahti wants to merge 5 commits into
python-kasa:masterfrom
rytilahti:fix/specific_tss_exception

Conversation

@rytilahti

Copy link
Copy Markdown
Member

We frequently receive reports from users who have issues with credentials.
One of the most common cases, besides the mobile app users' uppercasing the first letter, is due to the provisioning through "tplink simple setup" (tss) where the newly provisioned devices do not accept the regular credentials.

This PR adds a new exception that can be caught to display user a more detailed message about what they can do to fix the issue.

This has not been tested yet, so drafting for now.

Fixes #1573

@rytilahti rytilahti added the enhancement New feature or request label Oct 11, 2025
@codecov

codecov Bot commented Oct 11, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.62500% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.12%. Comparing base (8c66d0a) to head (4e71ac0).

Files with missing lines Patch % Lines
kasa/cli/discover.py 50.00% 5 Missing and 1 partial ⚠️
kasa/smart/smartdevice.py 55.55% 4 Missing ⚠️
kasa/discover.py 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1586      +/-   ##
==========================================
- Coverage   93.21%   93.12%   -0.10%     
==========================================
  Files         157      157              
  Lines        9819     9845      +26     
  Branches     1005     1008       +3     
==========================================
+ Hits         9153     9168      +15     
- Misses        472      481       +9     
- Partials      194      196       +2     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ZeliardM

Copy link
Copy Markdown
Collaborator

@rytilahti I wanted to let you know that I had a user report an issue with the homebridge-kasa-python plugin about this but the obd_src was "amazon_atr" and it was discovering the device but failing to authenticate until they re-added it as "tplink".

@github-actions

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added stale and removed stale labels Jan 22, 2026
@github-actions

Copy link
Copy Markdown

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
If you are the author of this PR, please leave a comment if you want to keep it open. Also, please rebase your PR onto the latest dev branch to ensure that it's up to date with the latest changes.
Thank you for your contribution!

@github-actions github-actions Bot added stale and removed stale labels Apr 23, 2026
@rytilahti
rytilahti marked this pull request as ready for review July 10, 2026 22:17
@rytilahti
rytilahti force-pushed the fix/specific_tss_exception branch from d6c3584 to f21fb36 Compare July 10, 2026 22:31
@rytilahti
rytilahti requested a review from ZeliardM July 10, 2026 22:31
Comment thread kasa/smart/smartdevice.py
Comment on lines +273 to +276
try:
await self._update(update_children)
except AuthenticationError as ex:
obd_src = self._discovery_info and self._discovery_info.get("obd_src")

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is done here as we do not know during the discovery time, pre-update, if the credentials are wrong or if we do not just support the authentication.

The known good sources are based on our fixtures, tss and amazon's obd are not supported, but maybe there exists also others, so we do not want to raise during the discovery to avoid raising unnecessarily.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this should be fine for now and when we go through the discovery process completely, we can handle authentication and unsupported errors separately.

@rytilahti rytilahti added this to the 0.11 milestone Jul 10, 2026
Comment thread kasa/cli/discover.py
try:
await dev.update()
except UnsupportedAuthenticationError as ex:
await print_unsupported(ex)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If print_discovered already holds the sem, calling print_unsupported will try to grab the same sem and cause a deadlock.

Comment thread kasa/cli/discover.py
try:
await dev.update()
except UnsupportedAuthenticationError as ex:
await print_unsupported(ex)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Same as above, right?

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.

Improve incorrect credentials handling for tss provisioning

2 participants