Handle unknown error codes gracefully (#1016)

Makes unknown error codes to be reported through KasaException which may
be recoverable in some cases (i.e., a single command failing in the
multi request).

Related to https://github.com/home-assistant/core/issues/118446
This commit is contained in:
Teemu R
2024-06-27 16:58:45 +02:00
committed by GitHub
parent 0a85243199
commit cf24a94526
5 changed files with 65 additions and 2 deletions

View File

@@ -239,12 +239,20 @@ class SmartProtocol(BaseProtocol):
response_result[response_list_name].extend(next_batch[response_list_name])
def _handle_response_error_code(self, resp_dict: dict, method, raise_on_error=True):
error_code = SmartErrorCode(resp_dict.get("error_code")) # type: ignore[arg-type]
error_code_raw = resp_dict.get("error_code")
try:
error_code = SmartErrorCode(error_code_raw) # type: ignore[arg-type]
except ValueError:
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
if error_code == SmartErrorCode.SUCCESS:
return
if not raise_on_error:
resp_dict["result"] = error_code
return
msg = (
f"Error querying device: {self._host}: "
+ f"{error_code.name}({error_code.value})"