GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix IOT KLAPv2 transport selection and class detection by thatdaveguy1 · Pull Request #1692 · python-kasa/python-kasa

Conversation

@thatdaveguy1

@thatdaveguy1 thatdaveguy1 commented Apr 18, 2026

Copy link
Copy Markdown

Summary

This PR fixes two related regressions for IOT KLAP devices on newer firmware:

  1. Transport selection: Use KlapTransportV2 for IOT KLAP devices when login_version >= 2.
  2. Device class detection: For IOT plug/switch and bulb families, derive class from system.get_sysinfo during connect() (not family-only mapping), so strips are correctly instantiated as IotStrip instead of IotPlug.

Why

  • IOT devices with KLAP encryption and login_version=2 use wrong transport (KlapTransport instead of KlapTransportV2) #1648 tracks IOT KLAP v2 auth failures caused by selecting KlapTransport for devices that require v2.
  • IOT KLAP devices can be misclassified as IotPlug (missing children) #1691 tracks IOT KLAP misclassification where strips lose child outlets because _connect() only used sysinfo-based class detection for XOR.

Tests

  • Added iot-klap-lv2 coverage in test_get_protocol to assert KlapTransportV2 for login v2.
  • Added test_connect_iot_klap_uses_sysinfo_for_device_class to ensure KLAP strips are identified from sysinfo and not misclassified as plugs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

2myaus, bradcarnage, mmcnl, and mkaminsky reacted with thumbs up emoji bradcarnage and mmcnl reacted with heart emoji bradcarnage reacted with rocket emoji
All reactions
  • 👍 4 reactions
  • ❤️ 2 reactions
  • 🚀 1 reaction
@nginxhijinx
Fix IOT KLAPv2 transport and class detection
8b1f6b8
Use KlapTransportV2 for IOT KLAP devices with login_version >= 2 and derive IOT plug/switch+b ulb classes from get_sysinfo so strips are not misclassified as plugs.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings April 18, 2026 17:26
This was referenced Apr 18, 2026
IOT devices with KLAP encryption and login_version=2 use wrong transport (KlapTransport instead of KlapTransportV2) #1648
Closed
IOT KLAP devices can be misclassified as IotPlug (missing children) #1691
Closed
Copilot started reviewing on behalf of thatdaveguy1 April 18, 2026 17:26
View session
@codecov

codecov Bot commented Apr 18, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (76d9f68) to head (8b1f6b8).
⚠️ Report is 21 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1692   +/-   ##
=======================================
  Coverage   93.22%   93.22%           
=======================================
  Files         157      157           
  Lines        9815     9817    +2     
  Branches     1003     1004    +1     
=======================================
+ Hits         9150     9152    +2     
  Misses        472      472           
  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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI reviewed Apr 18, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Pull request overview

Fixes regressions affecting IOT devices using KLAP on newer firmware by selecting the correct KLAP transport for login v2 and ensuring correct device-class instantiation (e.g., strips vs plugs) based on system.get_sysinfo during connect().

Changes:

  • Select KlapTransportV2 for IOT KLAP devices when login_version >= 2.
  • Use system.get_sysinfo-based device class detection during connect() for IOT plug/switch and bulb families (not just XOR).
  • Add unit tests covering both transport selection and KLAP device-class detection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
kasa/device_factory.py Adjusts IOT connect path to derive class from sysinfo for plugs/bulbs and selects KlapTransportV2 for IOT KLAP login v2.
tests/test_device_factory.py Adds tests asserting IOT KLAP login v2 uses KlapTransportV2 and that KLAP strips are instantiated via sysinfo detection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bradcarnage

bradcarnage commented May 25, 2026

Copy link
Copy Markdown

✅ Independently confirmed this fix works on real hardware.

I hit this exact bug on an HS103 (US) HW 5.0, FW 1.1.3 Build 250908 running on Home Assistant 2026.5.4 (python-kasa 0.10.2). Device reports with in discovery, but mapped it to (v1, MD5) — causing .

I independently arrived at the same fix (upgrading to when ) before finding this PR. Validated by:

  1. Raw KLAP handshake1+2 with SHA-based (v2) hashes → ✅ success
  2. Raw KLAP handshake1 with MD5-based (v1) hashes → ❌ mismatch
  3. Patching identically to this PR → device fully controllable via python-kasa and HA

This is blocking real HA users — anyone with HS103/HS200/HS300/KP303 on newer firmware (HW 5.0+) can't add these devices. The fix is minimal, correct, and well-tested. Would love to see this merged. 🚀

mmcnl reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced May 25, 2026
feat(klaptransport): auto-detect KLAP v2 for IOT devices #1625
Closed
Unable to authenticate: Device response did not match our challenge on ip 192.xxx.x.xxx, check that your e-mail and password (both case-sensitive) are correct home-assistant/core#164777
Closed
@carterbs

carterbs commented Jun 12, 2026

Copy link
Copy Markdown

Hey Brad! Another Brad here confirming this against real hardware.

I hit the same failure path in Home Assistant with a TP-Link HS103:

  • Home Assistant Core: 2026.1.3
  • python-kasa: 0.10.2
  • Device: HS103(US), HW 5.0
  • Discovery metadata:
    • device_type: IOT.SMARTPLUGSWITCH
    • mgt_encrypt_schm.encrypt_type: KLAP
    • mgt_encrypt_schm.http_port: 80
    • mgt_encrypt_schm.lv: 2
    • mgt_encrypt_schm.new_klap: 1

Before applying this patch, Home Assistant/python-kasa selected the normal KlapTransport path for IOT.KLAP and failed during handshake1:

Finding protocol for 192.168.5.241
Finding transport for IOT.KLAP
Created KLAP transport for 192.168.5.241
Handshake1 success ... Response status is 200
Device response did not match our challenge on ip 192.168.5.241

I applied the same selection logic from this PR inside the HA container and restarted HA. A direct transport-selection probe then showed:

login_version None -> KlapTransport
login_version 1    -> KlapTransport
login_version 2    -> KlapTransportV2

After that, the HS103 began authenticating/querying successfully from Home Assistant:

Device 192.168.5.241 query posted ... Response status is 200
Device 192.168.5.241 query response received
Finished fetching 192.168.5.241 data ... success: True

So this is another confirmation that IOT KLAP devices advertising lv: 2 / new_klap: 1 need KlapTransportV2; otherwise valid TP-Link credentials fail with the challenge mismatch. This PR is the minimal fix for the behavior I observed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

benbenmoss
benbenmoss reviewed Jun 13, 2026
View reviewed changes

@benbenmoss benbenmoss left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Reviewed and tested.

  • Code change is minimal and well-scoped: correctly selects KlapTransportV2 for IOT KLAP devices with login_version >= 2, and fixes device-class detection (sysinfo-based) for IOT plug/bulb families so strips aren't misclassified as plugs (#1691).
  • tests/test_device_factory.py passes (1287 passed) with the new iot-klap-lv2 and sysinfo-class-detection cases.
  • Ran the full test suite on this branch vs master: the 182 test_discover_raw failures are pre-existing on master too -- unrelated to this change.
  • Live-tested against my own SMART.TAPOHUB (H110, KLAP login_version 2) on this branch -- connects and updates correctly, confirming no regression to the existing SMART KLAP path.
  • Combined with the real-hardware confirmations from @bradcarnage (HS103) and @carterbs (HS103) above, this fixes #1648 and #1691 for IOT KLAP v2 devices (HS103/HS200/HS300/KP303 on newer firmware).

LGTM -- recommend merging.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bradcarnage

bradcarnage commented Jun 18, 2026

Copy link
Copy Markdown

paging @rytilahti to review this PR

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@michaelpetrov

michaelpetrov commented Jul 2, 2026

Copy link
Copy Markdown

I independently validated this failure and the two-part fix against a real HS300 power strip through Home Assistant.

Environment and device:

  • Home Assistant Core: 2026.6.4
  • python-kasa: 0.10.2
  • Device: HS300(US)
  • Discovery/device data:
    • device_type: IOT.SMARTPLUGSWITCH
    • mgt_encrypt_schm.encrypt_type: KLAP
    • mgt_encrypt_schm.http_port: 80
    • mgt_encrypt_schm.lv: 2
    • mgt_encrypt_schm.new_klap: 1
    • port 80 open, port 9999 closed

Stock HA / python-kasa 0.10.2 failed immediately during reauth with valid TP-Link credentials:

Device response did not match our challenge

A direct KLAP v2 handshake succeeded with the same credentials, and IotProtocol + KlapTransportV2 was able to query the device successfully. I then patched HA's vendored integration locally with the same two behavioral changes as this PR:

  1. select KlapTransportV2 for IOT.KLAP when login_version >= 2
  2. use system.get_sysinfo during connect to pick the concrete IOT device class

After restarting HA, the reconfigure flow completed successfully and the config entry stored the credential hash. The sysinfo/class-detection part was also required: without that path, this HS300 gets treated as a generic IotPlug, losing the strip children. With both parts of the fix in place, HA created the strip plus all child outlets and energy/voltage sensors as available.

So this PR matches the fix required for HS300 as well as the HS103 confirmations above: the transport change fixes auth, and the sysinfo class detection fixes child outlet/entity creation for strips.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

benbenmoss
benbenmoss approved these changes Jul 2, 2026
View reviewed changes

@benbenmoss benbenmoss left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGMT

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
This was referenced Jul 6, 2026
Kasa KLAP recovery falls back to XOR and blanks UI during credential reload the-hcma/domesti-bot#410
Closed
fix: improve KLAP recovery and keep Kasa tiles during rediscover (closes #410) the-hcma/domesti-bot#411
Merged
chore: revert python-kasa git pin to PyPI the-hcma/domesti-bot#433
Closed
@ZeliardM

ZeliardM commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

There is already an existing, extensively tested PR that handles all of the CLI and API changes, #1580, we are working to get this implemented and a new version released soon.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pww217 pww217 mentioned this pull request Jul 27, 2026
KLAP v2 Authentication Failure on TP-Link HS300 (US) — Hardware Version 2.0 #1604
Open
@azuttre

azuttre commented Sep 2, 2026

Copy link
Copy Markdown

Adding KP303 power-strip evidence for the two changes in this PR, also relevant to #1580.

On 2026-09-02 I upgraded Home Assistant Core from 2026.7.2 to 2026.8.3, retaining a local backport on python-kasa 0.10.2 that:

  • selects KlapTransportV2 for IOT KLAP with login_version >= 2;
  • uses system.get_sysinfo to identify the concrete IOT device class, including strips and their children.

After replacing the HA container and restarting, the real KP303 parent and all three child outlets were still present. The outlet states remained one ON and two OFF, matching the pre-upgrade snapshot; none of those outlets became unavailable.

The candidate image also passed isolated checks with networking disabled: login version 1 selects KlapTransport, version 2 selects KlapTransportV2, and a get_sysinfo response containing children resolves to IotStrip.

Scope: this is evidence for an equivalent local backport and its HA restart/upgrade behavior, not a test of the complete #1692 or #1580 branch. The isolated class test calls the sysinfo class resolver, not the full connect() path. I did not issue physical outlet-toggle commands during this maintenance check, and I have not captured hardware/firmware revisions for this report.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Lucas-Berthou

Lucas-Berthou commented Sep 11, 2026

Copy link
Copy Markdown

I tried using this change for 2 of my HS200 that I updated and that stopped responding, it didn't work.
#1580 on the other hand worked right away.
Thanks for the great work though!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@LTKMN LTKMN mentioned this pull request Sep 16, 2026
Support new_klap IoT devices #1580
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
+1 more reviewer
@benbenmoss benbenmoss benbenmoss approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@thatdaveguy1 @bradcarnage @carterbs @michaelpetrov @ZeliardM @azuttre @Lucas-Berthou @benbenmoss @nginxhijinx
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.