FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Support multiple child requests by sdb9696 · Pull Request #795 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 8 additions & 2 deletions kasa/smartprotocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,16 @@ async def query(self, request: Union[str, Dict], retry_count: int = 3) -> Dict:
result = response.get("control_child")
# Unwrap responseData for control_child
if result and (response_data := result.get("responseData")):
self._handle_response_error_code(response_data, "control_child")
result = response_data.get("result")
if result and (multi_responses := result.get("responses")):
ret_val = {}
for multi_response in multi_responses:
method = multi_response["method"]
self._handle_response_error_code(multi_response, method)
ret_val[method] = multi_response.get("result")
return ret_val

# TODO: handle multipleRequest unwrapping
self._handle_response_error_code(response_data, "control_child")

return {method: result}

Expand Down
14 changes: 6 additions & 8 deletions kasa/tests/test_smartprotocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ async def test_childdevicewrapper_error(dummy_protocol, mocker):
await wrapped_protocol.query(DUMMY_QUERY)


@pytest.mark.skip("childprotocolwrapper does not yet support multirequests")
async def test_childdevicewrapper_unwrapping_multiplerequest(dummy_protocol, mocker):
"""Test that unwrapping multiplerequest works correctly."""
mock_response = {
Expand All @@ -146,13 +145,12 @@ async def test_childdevicewrapper_unwrapping_multiplerequest(dummy_protocol, moc
}
},
}

mocker.patch.object(dummy_protocol._transport, "send", return_value=mock_response)
resp = await dummy_protocol.query(DUMMY_QUERY)
wrapped_protocol = _ChildProtocolWrapper("dummyid", dummy_protocol)
mocker.patch.object(wrapped_protocol._transport, "send", return_value=mock_response)
resp = await wrapped_protocol.query(DUMMY_QUERY)
assert resp == {"get_device_info": {"foo": "bar"}, "second_command": {"bar": "foo"}}


@pytest.mark.skip("childprotocolwrapper does not yet support multirequests")
async def test_childdevicewrapper_multiplerequest_error(dummy_protocol, mocker):
"""Test that errors inside multipleRequest response of responseData raise an exception."""
mock_response = {
Expand All @@ -172,7 +170,7 @@ async def test_childdevicewrapper_multiplerequest_error(dummy_protocol, mocker):
}
},
}

mocker.patch.object(dummy_protocol._transport, "send", return_value=mock_response)
wrapped_protocol = _ChildProtocolWrapper("dummyid", dummy_protocol)
mocker.patch.object(wrapped_protocol._transport, "send", return_value=mock_response)
with pytest.raises(KasaException):
await dummy_protocol.query(DUMMY_QUERY)
await wrapped_protocol.query(DUMMY_QUERY)

Back | FazBrowse Home | New Git URL