mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-08 16:38:01 +00:00
Cache SmartErrorCode creation (#1022)
Uses the python 3.9 cache feature to improve performance of error code creation
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user