mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-23 03:33:35 +00:00
Merge branch 'master' into feat/parent_child_updates
This commit is contained in:
commit
39fb238b67
@ -142,12 +142,11 @@ class AesTransport(BaseTransport):
|
||||
def _handle_response_error_code(self, resp_dict: Any, msg: str) -> None:
|
||||
error_code_raw = resp_dict.get("error_code")
|
||||
try:
|
||||
error_code = SmartErrorCode(error_code_raw) # type: ignore[arg-type]
|
||||
error_code = SmartErrorCode.from_int(error_code_raw)
|
||||
except ValueError:
|
||||
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
||||
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
||||
|
||||
if error_code == SmartErrorCode.SUCCESS:
|
||||
if error_code is SmartErrorCode.SUCCESS:
|
||||
return
|
||||
msg = f"{msg}: {self._host}: {error_code.name}({error_code.value})"
|
||||
if error_code in SMART_RETRYABLE_ERRORS:
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from asyncio import TimeoutError as _asyncioTimeoutError
|
||||
from enum import IntEnum
|
||||
from functools import cache
|
||||
from typing import Any
|
||||
|
||||
|
||||
@ -63,6 +64,12 @@ class SmartErrorCode(IntEnum):
|
||||
def __str__(self):
|
||||
return f"{self.name}({self.value})"
|
||||
|
||||
@staticmethod
|
||||
@cache
|
||||
def from_int(value: int) -> SmartErrorCode:
|
||||
"""Convert an integer to a SmartErrorCode."""
|
||||
return SmartErrorCode(value)
|
||||
|
||||
SUCCESS = 0
|
||||
|
||||
# Transport Errors
|
||||
|
@ -241,12 +241,12 @@ class SmartProtocol(BaseProtocol):
|
||||
def _handle_response_error_code(self, resp_dict: dict, method, raise_on_error=True):
|
||||
error_code_raw = resp_dict.get("error_code")
|
||||
try:
|
||||
error_code = SmartErrorCode(error_code_raw) # type: ignore[arg-type]
|
||||
error_code = SmartErrorCode.from_int(error_code_raw)
|
||||
except ValueError:
|
||||
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
||||
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
||||
|
||||
if error_code == SmartErrorCode.SUCCESS:
|
||||
if error_code is SmartErrorCode.SUCCESS:
|
||||
return
|
||||
|
||||
if not raise_on_error:
|
||||
|
Loading…
Reference in New Issue
Block a user