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

fix: query IoT HomeKit separately to avoid legacy device timeouts by cheeseandcereal · Pull Request #1792 · python-kasa/python-kasa · GitHub

Repository navigation

fix: query IoT HomeKit separately to avoid legacy device timeouts - #1792

Open
cheeseandcereal wants to merge 1 commit into
python-kasa:masterfrom
cheeseandcereal:fix/iot-homekit-query-batching
Open

cheeseandcereal wants to merge 1 commit into
python-kasa:masterfrom
cheeseandcereal:fix/iot-homekit-query-batching

Conversation

cheeseandcereal commented Oct 11, 2026 •
edited
Loading

Copy link
Copy Markdown

Summary

Send the IoT HomeKit query in its own request. Some legacy firmware times out when an unsupported smartlife.iot.homekit.setup_info_get query follows another module in a batch, preventing the entire device update from completing.

Fixes: #1791
Fixes: #1788

I've tested this fix on devices EP10, HS103 and KP115. A closely matching downstream report is home-assistant/core#185859.

Root cause

On the same devices and network path, python-kasa 0.10.2 completes initial and subsequent updates, while 0.11.0.1 times out. The probe was introduced in #1566.

This minimal request times out while waiting for the response header:

{"system":{"get_sysinfo":{}},"smartlife.iot.homekit":{"setup_info_get":{}}}

Reversing the two module keys succeeds. Sending HomeKit alone also succeeds and returns:

{"smartlife.iot.homekit":{"err_code":-1,"err_msg":"module not support"}}

This ordering behavior was reproduced on EP10(US) hardware 1.0 / firmware 1.0.2, HS103(US) hardware 5.0 / firmware 1.0.3, and KP115(US) hardware 1.0 / firmware 1.0.7. Full firmware build identifiers are in #1791.

Implementation

Keep HomeKit out of the normal modular-update batch and merge its response through the existing update path. Unsupported responses are cached by the existing module support detection, so subsequent updates omit the query. Supported HomeKit remains available. Genuine communication failures and cancellation still propagate.

The production change is six lines and avoids relying on JSON key ordering or model/firmware lists. Unsupported devices incur one additional request during initialization; supported devices query HomeKit separately during updates.

Validation

  • All seven tested plugs fail with published 0.11.0.1 and complete two updates with this patch: four HS103, two EP10 and one KP115.
  • One representative of each model completes two updates with published 0.10.2 and with a diagnostic standalone HomeKit probe on 0.11.0.1.
  • Patched EP10, HS103 and KP115 also pass on Python 3.14.8 with speedups, default retries and a disconnect between updates. KP115 energy readings remain available.
  • Regression tests simulate the measured firmware behavior and cover discovery-seeded/cold initialization, repeated updates, unsupported detection, supported EP25 HomeKit data, energy availability, strip-parent handling, timeouts, cancellation and recovery. The EP10 regression fails against unpatched production code.
  • uv run pytest -q -n 8 --timeout=30 --tb=short --maxfail=5: 23795 passed, 901 skipped.
  • uv run pre-commit run --files kasa/iot/iotdevice.py tests/iot/modules/test_homekit.py tests/iot/test_iotdevice.py: all applicable checks pass, including mypy.
  • git diff --check: passes.

codecov Bot commented Oct 11, 2026 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.45%. Comparing base (38a3184) to head (ee5061e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1792      +/-   ##
==========================================
+ Coverage   93.41%   93.45%   +0.04%     
==========================================
  Files         159      159              
  Lines       10113    10116       +3     
  Branches     1043     1044       +1     
==========================================
+ Hits         9447     9454       +7     
+ Misses        472      470       -2     
+ Partials      194      192       -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.

Copy link
Copy Markdown

Confirming this on HS110(UK) hw 4.1, fw 1.1.1 Build 201203 Rel.135822, the same model and firmware as #1788. I'm on HA 2026.10.1 with python-kasa 0.11.0.1. Discovery works, but the first update() times out three times on port 9999 and the config flow fails. An HS100(UK) hw 2.1 on fw 1.5.10 on the same network works normally.

I sent raw XOR requests directly to the plug, opening a new connection for each, with a 6 s timeout:

Request Result
system.get_sysinfo only OK, 0.03 s
smartlife.iot.homekit.setup_info_get only OK, 0.11 s, {"err_code":-1,"err_msg":"module not support"}
system + homekit Timeout
homekit + system OK, 0.02 s
system + foo.bar (made-up module) Timeout
system + emeter + homekit OK, 0.05 s, homekit returns module not support
emeter + homekit OK, 0.03 s
Full 0.11.0.1 first-update query Timeout
Same query with homekit removed OK, 0.06 s

This firmware matches @ewalker101's finding: it hangs whenever an unsupported module comes directly after system. HomeKit sent on its own returns the unsupported error cleanly, and the rest of the batch works without it, so the #1792 approach should work for this device. Because foo.bar after system also hangs, it may be worth covering that general case too, so a future module doesn't reintroduce the bug.

I haven't run the #1792 branch yet. I'm happy to test it if that helps.

Copy link
Copy Markdown

Confirmed the production change in this PR (ee5061e37ccad6bd95cd2cacaa812a9db773817f) restores two EP10(US), hardware 1.0, firmware 1.0.2 Build 200915 Rel.085940 plugs, both in an isolated macOS/Python 3.14 test and in Home Assistant OS 18.3 / Core 2026.10.1.

  • Published python-kasa==0.11.0.1: initial update times out on both physical plugs.
  • Exact candidate _modular_update method applied in memory: both complete two consecutive status updates, disconnecting between updates (approximately 0.12–0.27 seconds/update).
  • Same replacement loaded inside HA using a temporary startup custom component: after restart, both config entries are loaded and both switch entities recover.
  • HA switch.turn_on / switch.turn_off succeeds on both plugs. Independent direct get_sysinfo reads verify the real relays report 1 then 0; HA state publication settles in roughly one second. Both restored to their initial off state.

The temporary loader checks the exact library version and original/replacement source fingerprints, then constructs the replacement with FunctionType(candidate.__code__, original.__globals__, ...) and assigns it to IotDevice._modular_update. It uses the PR's unchanged method, retaining HomeKit queries as separate requests; it does not use the workaround that disables the HomeKit module. No installed library files, device firmware, cloud pairing, or firewall settings were changed, and no HA rollback was needed.

Full test results, installation method, guards, and limitations.

This confirms the PR's production change via a locally constructed runtime backport, rather than installing/testing the entire candidate package. I did not run the full upstream suite or test a HomeKit-capable device. This is immediate post-restart verification, not a long-term soak test.

psiberfunk commented Oct 17, 2026 •
edited
Loading

Copy link
Copy Markdown

For review: HS110(UK) hw 4.1 / fw 1.1.1 Build 201203 Rel.135822 is now confirmed too. That's the beta-firmware model from #1788, and the one gap #1791 called out. @AlecRust ran ee5061e on all three of their plugs: updates work, including after reconnecting, and energy readings are intact (comment on #1788).

So this commit now has real-hardware passes on EP10, HS103, KP115 and HS110(UK). KP100 (#1799) and HS200 (#1803) show the same failure signature but haven't been run against it yet.

Copy link
Copy Markdown

Another confirmation matching #1803:

  • HS200(US), hardware 5.0
  • Firmware 1.0.2 Build 200819 Rel.105309
  • HA Core upgraded from 2026.9.3 to 2026.10.2
  • python-kasa 0.11.0.1

The switch stopped initializing after the upgrade. Power cycling the switch and restarting HA did not help. The Kasa app still controlled it locally with internet access blocked.

HA debug logs showed standalone system.get_sysinfo succeeding in about 0.11 seconds. The combined initialization query, with smartlife.iot.homekit.setup_info_get immediately after system, repeatedly timed out waiting for the response header.

A version-guarded custom component making HomeKit.query() return {} restored initialization and normal switching from HA after a restart.

To clarify, this validates the probe-suppression workaround, not this PR’s separate-request implementation. Thanks for working on the long term fix!

Copy link
Copy Markdown

Tested PR #1792 against TP-Link KP100(US), hardware v3.0, firmware 1.0.1 Build 200831 Rel.142128.

Results:
python-kasa 0.10.2: Previously confirmed working.
python-kasa 0.11.0.1: Timeout during state query.

PR #1792 (ee5061e): Successfully retrieves device state.
Multiple consecutive state queries: Successful.

This confirms the proposed fix resolves the regression on KP100(US) hardware v3.0.

Thank you for working on this!

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

None yet

Projects

None yet

5 participants


Back | FazBrowse Home | New Git URL