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 — Keep multi requests for smartcam devices after a timeout by hugaraujo · Pull Request #1802 · python-kasa/python-kasa

Conversation

@hugaraujo

@hugaraujo hugaraujo commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Fixes #1801.

Problem

Since 0.11.0, a TimeoutError during a batched request permanently sets _multi_request_batch_size = 1 (added for the P300, which never answers some batches). For smartcam devices that is fatal: with batch size 1, _execute_multiple_query sends SMART-style single requests (get_smart_request), which cameras reject with PROTOCOL_FORMAT_ERROR (-40210). That error sets HANDSHAKE_REQUIRED, so every module query triggers a new handshake.

So a single network blip leaves the device object stuck forever. On four Tapo C100 (fw 1.5.7) in Home Assistant 2026.10.1 this meant ~30 logins/min per camera until they locked the account out (-40404, sec_left), and HA never recovered on its own. A fresh Device object worked immediately.

Fix

A class attribute CAN_DISABLE_MULTI_REQUESTS (true on SmartProtocol, false on SmartCamProtocol) guards both places that fall back to single requests: the timeout fallback and the JSON-decode fallback. For cameras the timeout is re-raised as before 0.11, so _query resets the transport and retries the batch. The P300 behaviour is unchanged.

Testing

  • New test test_smartcam_multiple_request_timeout_keeps_batching: a timeout followed by a successful batch keeps the batch size, and only multipleRequests are sent. It fails without the change.

  • pytest tests → 24022 passed, 905 skipped. ruff check, ruff format --check and mypy kasa/protocols are clean.

  • Live, against a real C100, through a local TCP proxy that drops camera→client bytes for 20 s to simulate a Wi-Fi blip, polling every 5 s (details in C100: one network timeout permanently disables multi-requests (0.11.0.1), single requests get -40210 → endless re-handshakes → lockout #1801):

    • 0.10.2: recovers after 1 failed poll, 2 handshakes.
    • 0.11.0.1: never recovers, 85 handshakes in about 4 min, 168× -40210.
    • 0.11.0.1 with batching kept after the timeout: 0 failed polls, 2 handshakes.

    The live run used an equivalent local patch (the batch size reset skipped). This exact diff is covered by the unit test.

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

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

All reactions
@hugaraujo @claude
Keep multi requests for smartcam devices after a timeout
5d9fdbc
A timeout during a batched request switched the protocol to batch size 1
permanently. SmartCamProtocol then sends SMART-style single requests, which
cameras reject with PROTOCOL_FORMAT_ERROR (-40210); every rejection forces a
new handshake, so a single Wi-Fi blip left C100 cameras re-authenticating
~30 times a minute until they locked the account out (-40404).

Only fall back to single requests on protocols that support them.

Fixes python-kasa#1801

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@codecov

codecov Bot commented Oct 14, 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.43%. Comparing base (f1a8d38) to head (ec205c3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1802   +/-   ##
=======================================
  Coverage   93.43%   93.43%           
=======================================
  Files         159      159           
  Lines       10116    10120    +4     
  Branches     1044     1045    +1     
=======================================
+ Hits         9452     9456    +4     
  Misses        471      471           
  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.

@hugaraujo hugaraujo mentioned this pull request Oct 14, 2026
C100: one network timeout permanently disables multi-requests (0.11.0.1), single requests get -40210 → endless re-handshakes → lockout #1801
Closed
rytilahti
rytilahti reviewed Oct 14, 2026
View reviewed changes
Comment thread kasa/protocols/smartcamprotocol.py Resolved

Uh oh!

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

@rytilahti rytilahti added the bug Something isn't working label Oct 14, 2026
@rytilahti rytilahti mentioned this pull request Oct 14, 2026
Tapo C200 controls become unavailable with PROTOCOL_FORMAT_ERROR (-40210); reload restores controls home-assistant/core#186172
Closed
@freeKC

freeKC commented Oct 14, 2026

Copy link
Copy Markdown
Contributor

Confirmed on a second model. On a Tapo C510W (fw 1.3.4, AES login) with master at d6e80d2: after a normal connect I set protocol._multi_request_batch_size = 1 and called update() again. Every module came back as INTERNAL_QUERY_ERROR (-100001) (getDeviceInfo, getConnectionType, getLastAlarmInfo, ...), i.e. the camera refuses the single requests. Setting the batch size back to 5 and resetting the transport, the next update() works again.

That is exactly the picture in home-assistant/core#186172: one of the two attached diagnostics has all 13 queries at -100001, the handshake keeps succeeding, and only a reload (a new protocol object, so the batch size back to its default) fixes it.

All reactions

Sorry, something went wrong.

Uh oh!

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

@hugaraujo @claude
Rename to REQUIRES_MULTIREQUESTS, shorten comments
ec205c3
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@freeKC freeKC mentioned this pull request Oct 17, 2026
TP-Link Tapo C110 becomes unavailable after successful handshake: Bad status line until config entry reload home-assistant/core#186951
Closed
rytilahti
rytilahti approved these changes Oct 20, 2026
View reviewed changes

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Member

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.

Thanks @hugaraujo! I did not yet test this on my test camera, but given the other reports this should be fine.

I will merge it in hopes more people can test it, and try to reproduce and test against my cam before doing a release later this week.

Sorry, something went wrong.

Uh oh!

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

All reactions
@rytilahti
rytilahti merged commit e29864b into python-kasa:master Oct 20, 2026
22 checks passed

Uh oh!

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

@jakubmachala jakubmachala mentioned this pull request Oct 21, 2026
H200 firmware 1.7.7 intermittently returns only 10/22 children; missing children are removed until reload #1804
Open
@JBendarr JBendarr mentioned this pull request Oct 24, 2026
TP-Link Tapo H200 child devices disappear from Home Assistant until integration is reconfigured home-assistant/core#186473
Closed
@rytilahti rytilahti mentioned this pull request Oct 25, 2026
Prepare 0.12.0 #1811
Merged
rytilahti added a commit that referenced this pull request Oct 25, 2026
@rytilahti
Prepare 0.12.0 (#1811)
a178fba
## [0.12.0](https://github.com/python-kasa/python-kasa/tree/0.12.0)
(2026-10-25)

This release include several compatibility fixes (updated accepted SSL
ciphers, removal of Homekit from the default update cycle).
The new API `Device.supports_module()` provide a way to find out if the
device supports some specific module, e.g., HomeKit, without including
it in the default update cycle.

[Full
Changelog](0.11.0.1...0.12.0)

**Fixed bugs:**

- Keep hub children when the child component list is missing
[\#1797](#1797)
(@Richardtristan)
- Strip multi-word rich tags when rich is not installed
[\#1807](#1807)
(@wolfgang-aura)
- Add Device.supports_module() and stop querying HomeKit for iot devices
[\#1808](#1808)
(@rytilahti)
- Keep multi requests for smartcam devices after a timeout
[\#1802](#1802)
(@hugaraujo)
- Consolidate SSL ciphers and use them in SslTransport
[\#1798](#1798)
(@rytilahti)
- Raise UnsupportedDeviceError instead of crashing on unknown device
types [\#1781](#1781)
(@GhostCoder6969)

**Added support for devices:**

- Add TD21(EU) device fixture
[\#1786](#1786)
(@Smugaski)
- Add P116M(IN) fixture
[\#1795](#1795)
(@Partha-dev01)

**Project maintenance:**

- Add Python 3.15 to supported versions and update pins
[\#1793](#1793)
(@rytilahti)
- Generate the changelog with git-cliff and draft releases in CI
[\#1809](#1809)
(@rytilahti)
- Build and check packages in CI and publish workflows
[\#1782](#1782)
(@rytilahti)

**Other changes:**

- Use the real discovery reply in the TD21 fixture
[\#1800](#1800)
(@Smugaski)
@rytilahti rytilahti mentioned this pull request Oct 25, 2026
Bump python-kasa to 0.12.0 home-assistant/core#188594
Merged
2 of 21 tasks
pillarsdotnet pushed a commit to pillarsdotnet/python-kasa that referenced this pull request Oct 30, 2026
@hugaraujo
Keep multi requests for smartcam devices after a timeout (python-kasa…
b965296
…#1802)

Smartcam devices do not support sending individual requests, but respond always with `PROTOCOL_FORMAT_ERROR
(-40210)`.

This commit forces them to always use the multi-request format for requests even after receiving an error where we would otherwise fallback to individual requests.
pillarsdotnet pushed a commit to pillarsdotnet/python-kasa that referenced this pull request Oct 30, 2026
@rytilahti
Prepare 0.12.0 (python-kasa#1811)
7ddf1ef
## [0.12.0](https://github.com/python-kasa/python-kasa/tree/0.12.0)
(2026-10-25)

This release include several compatibility fixes (updated accepted SSL
ciphers, removal of Homekit from the default update cycle).
The new API `Device.supports_module()` provide a way to find out if the
device supports some specific module, e.g., HomeKit, without including
it in the default update cycle.

[Full
Changelog](python-kasa/python-kasa@0.11.0.1...0.12.0)

**Fixed bugs:**

- Keep hub children when the child component list is missing
[\python-kasa#1797](python-kasa#1797)
(@Richardtristan)
- Strip multi-word rich tags when rich is not installed
[\python-kasa#1807](python-kasa#1807)
(@wolfgang-aura)
- Add Device.supports_module() and stop querying HomeKit for iot devices
[\python-kasa#1808](python-kasa#1808)
(@rytilahti)
- Keep multi requests for smartcam devices after a timeout
[\python-kasa#1802](python-kasa#1802)
(@hugaraujo)
- Consolidate SSL ciphers and use them in SslTransport
[\python-kasa#1798](python-kasa#1798)
(@rytilahti)
- Raise UnsupportedDeviceError instead of crashing on unknown device
types [\python-kasa#1781](python-kasa#1781)
(@GhostCoder6969)

**Added support for devices:**

- Add TD21(EU) device fixture
[\python-kasa#1786](python-kasa#1786)
(@Smugaski)
- Add P116M(IN) fixture
[\python-kasa#1795](python-kasa#1795)
(@Partha-dev01)

**Project maintenance:**

- Add Python 3.15 to supported versions and update pins
[\python-kasa#1793](python-kasa#1793)
(@rytilahti)
- Generate the changelog with git-cliff and draft releases in CI
[\python-kasa#1809](python-kasa#1809)
(@rytilahti)
- Build and check packages in CI and publish workflows
[\python-kasa#1782](python-kasa#1782)
(@rytilahti)

**Other changes:**

- Use the real discovery reply in the TD21 fixture
[\python-kasa#1800](python-kasa#1800)
(@Smugaski)
@DevilRange DevilRange mentioned this pull request Nov 5, 2026
Paginate list responses when multi requests are disabled #1838
Open
@MexicoCampingChronicles MexicoCampingChronicles mentioned this pull request Nov 6, 2026
Tapo C206 (HW 1.0, FW 1.3.1): intermittent INTERNAL_QUERY_ERROR (-100001) with python-kasa 0.12.0 #1842
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@rytilahti rytilahti rytilahti approved these changes

Uh oh!

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

Assignees

No one assigned

Labels

bug Something isn't working

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

C100: one network timeout permanently disables multi-requests (0.11.0.1), single requests get -40210 → endless re-handshakes → lockout

Uh oh!

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

3 participants

@hugaraujo @freeKC @rytilahti
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.