From 5782ce102985420d62f66ec63f31a139e33e987c Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Fri, 13 Dec 2024 14:39:55 +0000 Subject: [PATCH] Handle no method in multiple response for single request --- kasa/protocols/smartprotocol.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kasa/protocols/smartprotocol.py b/kasa/protocols/smartprotocol.py index 0e092547..3d74650a 100644 --- a/kasa/protocols/smartprotocol.py +++ b/kasa/protocols/smartprotocol.py @@ -246,7 +246,15 @@ class SmartProtocol(BaseProtocol): responses = response_step["result"]["responses"] for response in responses: - method = response["method"] + # smartcam devices sometimes do not populate method if there's + # only one item in the request + if ( + not (method := response.get("method")) + and "result" in response + and len(requests) == 1 + ): + method = next(iter(requests)) + self._handle_response_error_code( response, method, raise_on_error=raise_on_error )