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:
|
def _handle_response_error_code(self, resp_dict: Any, msg: str) -> None:
|
||||||
error_code_raw = resp_dict.get("error_code")
|
error_code_raw = resp_dict.get("error_code")
|
||||||
try:
|
try:
|
||||||
error_code = SmartErrorCode(error_code_raw) # type: ignore[arg-type]
|
error_code = SmartErrorCode.from_int(error_code_raw)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
||||||
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
||||||
|
if error_code is SmartErrorCode.SUCCESS:
|
||||||
if error_code == SmartErrorCode.SUCCESS:
|
|
||||||
return
|
return
|
||||||
msg = f"{msg}: {self._host}: {error_code.name}({error_code.value})"
|
msg = f"{msg}: {self._host}: {error_code.name}({error_code.value})"
|
||||||
if error_code in SMART_RETRYABLE_ERRORS:
|
if error_code in SMART_RETRYABLE_ERRORS:
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from asyncio import TimeoutError as _asyncioTimeoutError
|
from asyncio import TimeoutError as _asyncioTimeoutError
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
|
from functools import cache
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
@ -63,6 +64,12 @@ class SmartErrorCode(IntEnum):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}({self.value})"
|
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
|
SUCCESS = 0
|
||||||
|
|
||||||
# Transport Errors
|
# Transport Errors
|
||||||
|
@ -241,12 +241,12 @@ class SmartProtocol(BaseProtocol):
|
|||||||
def _handle_response_error_code(self, resp_dict: dict, method, raise_on_error=True):
|
def _handle_response_error_code(self, resp_dict: dict, method, raise_on_error=True):
|
||||||
error_code_raw = resp_dict.get("error_code")
|
error_code_raw = resp_dict.get("error_code")
|
||||||
try:
|
try:
|
||||||
error_code = SmartErrorCode(error_code_raw) # type: ignore[arg-type]
|
error_code = SmartErrorCode.from_int(error_code_raw)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
_LOGGER.warning("Received unknown error code: %s", error_code_raw)
|
||||||
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
error_code = SmartErrorCode.INTERNAL_UNKNOWN_ERROR
|
||||||
|
|
||||||
if error_code == SmartErrorCode.SUCCESS:
|
if error_code is SmartErrorCode.SUCCESS:
|
||||||
return
|
return
|
||||||
|
|
||||||
if not raise_on_error:
|
if not raise_on_error:
|
||||||
|
Loading…
Reference in New Issue
Block a user