FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cache SmartErrorCode creation by bdraco · Pull Request #1022 · python-kasa/python-kasa · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 2 additions & 3 deletions kasa/aestransport.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ def hash_credentials(login_v2: bool, credentials: Credentials) -> tuple[str, str
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:
Expand Down
7 changes: 7 additions & 0 deletions kasa/exceptions.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from asyncio import TimeoutError as _asyncioTimeoutError
from enum import IntEnum
from functools import cache
from typing import Any


Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions kasa/smartprotocol.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ async def _handle_response_lists(
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:
Expand Down

Back | FazBrowse Home | New Git URL