mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Re-query missing responses after multi request errors (#850)
When smart devices encounter an error during a multipleRequest they return the previous successes and the current error and stop processing subsequent requests. This checks the responses returned and re-queries individually for any missing responses so that individual errors do not break other components.
This commit is contained in:
@@ -113,6 +113,9 @@ class FakeSmartTransport(BaseTransport):
|
||||
responses = []
|
||||
for request in params["requests"]:
|
||||
response = self._send_request(request) # type: ignore[arg-type]
|
||||
# Devices do not continue after error
|
||||
if response["error_code"] != 0:
|
||||
break
|
||||
response["method"] = request["method"] # type: ignore[index]
|
||||
responses.append(response)
|
||||
return {"result": {"responses": responses}, "error_code": 0}
|
||||
|
@@ -36,6 +36,11 @@ async def test_smart_device_errors(dummy_protocol, mocker, error_code):
|
||||
async def test_smart_device_errors_in_multiple_request(
|
||||
dummy_protocol, mocker, error_code
|
||||
):
|
||||
mock_request = {
|
||||
"foobar1": {"foo": "bar", "bar": "foo"},
|
||||
"foobar2": {"foo": "bar", "bar": "foo"},
|
||||
"foobar3": {"foo": "bar", "bar": "foo"},
|
||||
}
|
||||
mock_response = {
|
||||
"result": {
|
||||
"responses": [
|
||||
@@ -55,9 +60,10 @@ async def test_smart_device_errors_in_multiple_request(
|
||||
dummy_protocol._transport, "send", return_value=mock_response
|
||||
)
|
||||
|
||||
resp_dict = await dummy_protocol.query(DUMMY_MULTIPLE_QUERY, retry_count=2)
|
||||
resp_dict = await dummy_protocol.query(mock_request, retry_count=2)
|
||||
assert resp_dict["foobar2"] == error_code
|
||||
assert send_mock.call_count == 1
|
||||
assert len(resp_dict) == len(mock_request)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("request_size", [1, 3, 5, 10])
|
||||
|
Reference in New Issue
Block a user