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

Raise UnsupportedDeviceError instead of crashing on unknown device types by GhostCoder6969 · Pull Request #1781 · python-kasa/python-kasa · GitHub

Repository navigation

Raise UnsupportedDeviceError instead of crashing on unknown device types - #1781

Merged
rytilahti merged 2 commits into
python-kasa:masterfrom
GhostCoder6969:fix-ipcamera-unsupported-oct4
Oct 12, 2026
Merged

rytilahti merged 2 commits into
python-kasa:masterfrom
GhostCoder6969:fix-ipcamera-unsupported-oct4

Conversation

Copy link
Copy Markdown
Contributor

I hit the same KeyError on my network, my EC60 shows up as IOT.IPCAMERA and the whole discovery run dies.

I changed get_device_class_from_sys_info so an unknown type raises UnsupportedDeviceError, which discovery already catches and reports as unsupported. I added a regression test for the legacy camera sysinfo and it realy fails without the fix.

Tests, uv run pytest tests/test_device_factory.py tests/test_discovery.py, 3568 passed. ruff check and ruff format clean. Fixes #1753

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

Interesting, that this has not caused issues earlier... Thanks for the PR @GhostCoder6969, I added a small nit on how I would personally make the check to keep it simpler. Take a look and let me know what you think!

Comment thread kasa/device_factory.py Outdated
device_type = IotDevice._get_device_type_from_sys_info(sysinfo)
try:
return TYPE_TO_CLASS[device_type]
except KeyError as ex:

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

Instead of try-catching, you could do something like:

if (cls := TYPE_TO_CLASS.get(device_type) is None:
    # raise exception

return cls 

Copy link
Copy Markdown
Contributor Author

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

Good call, much cleaner. I switched it to the get with None check and the tests still pass. Thanks for looking at it.

rytilahti added the bug Something isn't working label Oct 4, 2026
rytilahti changed the title I fixed the crash when discovery meets a camera it does not support yet Raise UnsupportedDeviceError instead of crashing on unknown device types Oct 4, 2026

codecov Bot commented Oct 4, 2026 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.43%. Comparing base (5b8447c) to head (55b8bfe).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1781      +/-   ##
==========================================
+ Coverage   93.42%   93.43%   +0.01%     
==========================================
  Files         159      159              
  Lines       10113    10116       +3     
  Branches     1043     1044       +1     
==========================================
+ Hits         9448     9452       +4     
+ Misses        472      471       -1     
  Partials      193      193              

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

Copy link
Copy Markdown
Contributor Author

Switched to the get with None check like you suggested, tests still green on my end.

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

LGTM, great to see changes making the discovery path more robust, thanks @GhostCoder6969!

rytilahti enabled auto-merge (squash) October 12, 2026 21:29
rytilahti disabled auto-merge October 12, 2026 21:29
rytilahti merged commit a4fe376 into python-kasa:master Oct 12, 2026
21 of 22 checks passed
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

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsupported IOT.IPCAMERA devices raise a bare KeyError from get_device_class_from_sys_info during discovery (fix written in #1571, closed by stale bot)

2 participants


Back | FazBrowse Home | New Git URL