FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Expose better authentication errors by blakeembrey · Pull Request #1742 · python-kasa/python-kasa · GitHub

Expose better authentication errors - #1742

Open
blakeembrey wants to merge 1 commit into
python-kasa:masterfrom
blakeembrey:be/helpful-auth-errors
Open

Expose better authentication errors#1742
blakeembrey wants to merge 1 commit into
python-kasa:masterfrom
blakeembrey:be/helpful-auth-errors

Conversation

Copy link
Copy Markdown

I was trying to set up the P316M but run into a bunch of issues, these failures would have helped me a lot earlier. I'm sure it could still be further improved, but it's what worked for me.

Debug process:

  1. Username/password many times that kept failing (obd_src=tss)
  2. Removed and re-added device (obd_src=tplink, still didn't work)
  3. Factory reset and re-add (worked)

Prior to diving into this package I had assumed the board was either broken or unsupported. I tried more than I should have to re-authenticate in the home assistant UI.

Comment thread kasa/smart/smartdevice.py
owner = discovery_info.get("owner")
if credentials and self._is_owner_hash(owner):
supplied_owner = hashlib.md5( # noqa: S324
credentials.username.encode()

codecov Bot commented Aug 20, 2026
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.47619% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.27%. Comparing base (a29d061) to head (d6a2f6c).

Files with missing lines Patch % Lines
kasa/smart/smartdevice.py 88.23% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1742      +/-   ##
==========================================
- Coverage   93.29%   93.27%   -0.02%     
==========================================
  Files         157      157              
  Lines        9932     9967      +35     
  Branches     1022     1030       +8     
==========================================
+ Hits         9266     9297      +31     
- Misses        471      473       +2     
- Partials      195      197       +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.

rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Hi @blakeembrey and thanks for your PR! I think this would be really useful addition, I added a couple of things that should be taken care of before this can be merged.

Comment thread kasa/smart/smartdevice.py
return error

@staticmethod
def _is_owner_hash(owner: Any) -> TypeGuard[str]:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could we avoid typeguard import, set correct type for the input parameter, and make it return a regular bool?

Comment thread kasa/smart/smartdevice.py
supplied_owner = hashlib.md5( # noqa: S324
credentials.username.encode()
).hexdigest()
if supplied_owner.casefold() != owner.casefold():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would you mind moving this logic into a better place (likely to the corresponding auth protocol) and make it reusable?

Logic to detect mistyped username (I always assumed it'd be incorrect casing) would be useful, and we could try that to help people with issues like:

rytilahti added the enhancement New feature or request label Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL