GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — Split KLAP IoT updates into smaller requests and validate KLAP responses by ZeliardM · Pull Request #1829 · python-kasa/python-kasa Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@ ## master #1829 +/- ## ========================================== + Coverage 93.49% 93.50% +0.01% ========================================== Files 161 161 Lines 10159 10169 +10 Branches 1050 1053 +3 ========================================== + Hits 9498 9509 +11 Misses 469 469 + Partials 192 191 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Some KLAP IoT devices answer a request they reject with a plain "<html><body><center>200 OK</center></body></html>" page instead of a KLAP message: KS200M fw 1.1.4 (python-kasa#1828), HS100(UK) hw 4.1 fw 1.1.0 (python-kasa#1790) and KL125 fw 1.1.1. With an http status line the page failed to decrypt, without one aiohttp failed with "Bad status line". KlapTransport now raises _InvalidResponseError for a response that can't be a KLAP message, and HttpClient raises it when aiohttp can't parse the response. When an IoT update fails with it, the device queries each module in its own request from then on and retries the update once, like SmartProtocol disables multi requests. Strip outlets share the setting of their parent, whose connection they use. This replaces the KS200M-only response size cap. Fixes python-kasa#1828 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The skip moved into _query_modules and had no test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Added a quick comment about having a new exception type to handle this, but instead of doing a fallback to individual requests, we should IMO figure out if we can handle this otherwise. The reason being, that if this is fixable by making some queries optional and/or using the existing facilities to split the query sizes to avoid the issue, it would avoid so many extra queries. Wdyt?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Over KLAP, some IoT devices answer a request whose response would be larger than about 4 KiB with a plain "200 OK" html page instead of a KLAP message, and have less room right after a state change. Use a 2048 byte max_device_response_size for IoT devices on KLAP, so the update is split by the existing response size estimates, the same way bulbs use 4096. Bulbs keep 4096 and XOR devices keep 16 KiB. This replaces the KS200M-only cap, the per-module fallback and the internal _InvalidResponseError from the earlier commits on this branch. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A KLAP response is a 32 byte signature followed by whole AES blocks, signed for the sequence number of the request. Some devices answer with a plain "200 OK" html page instead, which failed later with "The length of the provided data is not a multiple of the block length". Check the length, block alignment and signature first, and raise a KasaException that says what was wrong and, for a body that is not a KLAP message, shows its start. As before, IotProtocol does not retry and resets the session, so the next query does a new handshake. The logging test's fake device signed its response for the next sequence number; it now signs for the request's, as devices do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks, agreed. The fallback is gone. The limit turned out to be on the size of the response, so the existing split covers it:
So updates over KLAP now use a 2048 response budget, and bulbs keep their 4096. That costs a few more requests per update (numbers in the description). The Kasa app sends each method in its own request, so it never sends a combined update. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I was thinking if we should split some of the tests out from iotdevice tests as they would fit better to the transport tests, but it is fine as-is. Great test additions, thanks!
This likely fixes also #1837?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Not sure if it will resolve that or if 0.12.0 when we removed HomeKit will. I'm asking them to check before we make any other changes. I'm looking into splitting the tests up and will let you know. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The 2048 byte budget and the KS200M split only apply over KLAP, so their tests now sit with the other KLAP tests, as suggested in review. tests/iot/test_iotdevice.py and tests/iot/test_wallswitch.py are back to their master versions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
I moved the KLAP-only tests into
Both IoT test files are back to master, so all of this PR's tests are in the KLAP test file now. I also merged master. Could you take another look? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Brings in python-kasa#1829 (smaller KLAP IoT update requests and KLAP response validation). No conflicts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks ZeliardM, and thanks again for the fix. The fork branch had already been merged and deleted, so I ran the test on the final PR head ba87779 (9c2fbad or later). Local size cap was off; plugin was stock homebridge-kasa-python 3.3.0-beta.8. Early readout (~3.4 h since this morning on six KS200Ms), against the Nov 1-5 baseline on 7688617 (95.5 h: decrypt/offline/200-OK all 0, 2 poll-failed timeouts, 664 toggles):
Homebridge and the plugin's Python process stayed up the whole window. All 22 toggles landed after the grace was removed. Looking good so far; happy to keep it running and post a longer readout later if useful. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
KS200M: combined update gets a plain "200 OK" html page instead of a KLAP response
There was an error while loading. Please reload this page.