mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-25 06:03:01 +00:00
Keep multi requests for smartcam devices after a timeout (#1802)
Some checks failed
CI / Perform Lint Checks (3.14) (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.14 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.14 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CI / Python 3.14 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled
Some checks failed
CI / Perform Lint Checks (3.14) (push) Has been cancelled
CodeQL Checks / Analyze (python) (push) Has been cancelled
CI / Python 3.11 on macos-latest (push) Has been cancelled
CI / Python 3.12 on macos-latest (push) Has been cancelled
CI / Python 3.13 on macos-latest (push) Has been cancelled
CI / Python 3.14 on macos-latest (push) Has been cancelled
CI / Python 3.11 on ubuntu-latest (push) Has been cancelled
CI / Python 3.12 on ubuntu-latest (push) Has been cancelled
CI / Python 3.13 on ubuntu-latest (push) Has been cancelled
CI / Python 3.14 on ubuntu-latest (push) Has been cancelled
CI / Python 3.11 on windows-latest (push) Has been cancelled
CI / Python 3.12 on windows-latest (push) Has been cancelled
CI / Python 3.13 on windows-latest (push) Has been cancelled
CI / Python 3.14 on windows-latest (push) Has been cancelled
Stale / stale (push) Has been cancelled
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.
This commit is contained in:
@@ -333,6 +333,39 @@ async def test_smart_device_multiple_request_child_lists_timeout(
|
||||
assert send_mock.call_count == 3
|
||||
|
||||
|
||||
async def test_smartcam_multiple_request_timeout_keeps_batching(
|
||||
dummy_protocol: SmartProtocol, mocker: MockerFixture
|
||||
) -> None:
|
||||
"""Test that a timeout does not disable batching for smartcam devices."""
|
||||
protocol = SmartCamProtocol(transport=dummy_protocol._transport)
|
||||
requests = {f"get_method_{i}": {"foo": "bar"} for i in range(3)}
|
||||
batch_response = {
|
||||
"result": {
|
||||
"responses": [
|
||||
{"method": method, "result": {"great": "success"}, "error_code": 0}
|
||||
for method in requests
|
||||
]
|
||||
},
|
||||
"error_code": 0,
|
||||
}
|
||||
|
||||
send_mock = mocker.patch.object(
|
||||
protocol._transport,
|
||||
"send",
|
||||
side_effect=[TimeoutError("Simulated timeout"), batch_response],
|
||||
)
|
||||
mocker.patch("asyncio.sleep")
|
||||
batch_size = protocol._multi_request_batch_size
|
||||
assert batch_size > 1
|
||||
resp = await protocol.query(requests, retry_count=1)
|
||||
assert resp == {method: {"great": "success"} for method in requests}
|
||||
assert protocol._multi_request_batch_size == batch_size
|
||||
# The timed out batch + the retried batch, no single requests
|
||||
assert send_mock.call_count == 2
|
||||
for call in send_mock.call_args_list:
|
||||
assert json.loads(call.args[0])["method"] == "multipleRequest"
|
||||
|
||||
|
||||
async def test_childdevicewrapper_unwrapping(
|
||||
dummy_protocol: SmartProtocol, mocker: MockerFixture
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user