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

@@ -140,7 +140,13 @@ class AesTransport(BaseTransport):
return un, pw
def _handle_response_error_code(self, resp_dict: Any, msg: str) -> None:
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
msg = f"{msg}: {self._host}: {error_code.name}({error_code.value})"