Do not raise on multi-request errors on child devices (#949)

This will avoid crashing when some commands return an error on
multi-requests on child devices.

Idea from
https://github.com/python-kasa/python-kasa/pull/900/files#r1624803457
This commit is contained in:
Teemu R 2024-06-03 20:41:55 +02:00 committed by GitHub
parent be5202ccb7
commit 22347381bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -402,7 +402,9 @@ class _ChildProtocolWrapper(SmartProtocol):
ret_val = {} ret_val = {}
for multi_response in multi_responses: for multi_response in multi_responses:
method = multi_response["method"] method = multi_response["method"]
self._handle_response_error_code(multi_response, method) self._handle_response_error_code(
multi_response, method, raise_on_error=False
)
ret_val[method] = multi_response.get("result") ret_val[method] = multi_response.get("result")
return ret_val return ret_val

View File

@ -181,8 +181,9 @@ async def test_childdevicewrapper_multiplerequest_error(dummy_protocol, mocker):
} }
wrapped_protocol = _ChildProtocolWrapper("dummyid", dummy_protocol) wrapped_protocol = _ChildProtocolWrapper("dummyid", dummy_protocol)
mocker.patch.object(wrapped_protocol._transport, "send", return_value=mock_response) mocker.patch.object(wrapped_protocol._transport, "send", return_value=mock_response)
with pytest.raises(KasaException): res = await wrapped_protocol.query(DUMMY_QUERY)
await wrapped_protocol.query(DUMMY_QUERY) assert res["get_device_info"] == {"foo": "bar"}
assert res["invalid_command"] == SmartErrorCode(-1001)
@pytest.mark.parametrize("list_sum", [5, 10, 30]) @pytest.mark.parametrize("list_sum", [5, 10, 30])