8000 Enum to IntEnum and SLEEP_SECONDS_AFTER_TIMEOUT · python-kasa/python-kasa@ea2d9fd · GitHub
[go: up one dir, main page]

Skip to content

Commit ea2d9fd

Browse files
committed
Enum to IntEnum and SLEEP_SECONDS_AFTER_TIMEOUT
1 parent aec623e commit ea2d9fd

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

kasa/aestransport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ async def client_post(self, url, params=None, data=None, json=None, headers=None
121121

122122
def _handle_response_error_code(self, resp_dict: dict, msg: str):
123123
if (
124-
error_code := SmartErrorCode(resp_dict.get("error_code"))
124+
error_code := SmartErrorCode(resp_dict.get("error_code")) # type: ignore[arg-type]
125125
) != SmartErrorCode.SUCCESS:
126126
msg = f"{msg}: {self.host}: {error_code.name}({error_code.value})"
127127
if error_code in SMART_TIMEOUT_ERRORS:

kasa/exceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""python-kasa exceptions."""
2-
from enum import Enum
2+
from enum import IntEnum
33

44

55
class SmartDeviceException(Exception):
@@ -22,7 +22,7 @@ class TimeoutException(SmartDeviceException):
2222
"""Timeout exception for device errors."""
2323

2424

25-
class SmartErrorCode(Enum):
25+
class SmartErrorCode(IntEnum):
2626
"""Enum for SMART Error Codes."""
2727

2828
SUCCESS = 0

kasa/smartprotocol.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SmartProtocol(TPLinkProtocol):
3737
"""Class for the new TPLink SMART protocol."""
3838

3939
DEFAULT_PORT = 80
40+
SLEEP_SECONDS_AFTER_TIMEOUT = 1
4041

4142
def __init__(
4243
self,
@@ -75,7 +76,7 @@ async def query(self, request: Union[str, Dict], retry_count: int = 3) -> Dict:
7576
resp_dict = await self._query(request, retry_count)
7677

7778
if (
78-
error_code := SmartErrorCode(resp_dict.get("error_code"))
79+
error_code := SmartErrorCode(resp_dict.get("error_code")) # type: ignore[arg-type]
7980
) != SmartErrorCode.SUCCESS:
8081
msg = (
8182
f"Error querying device: {self.host}: "
@@ -117,7 +118,7 @@ async def _query(self, request: Union[str, Dict], retry_count: int = 3) -> Dict:
117118
"Unable to connect to the device, "
118119
+ f"timed out: {self.host}: {tex}"
119120
) from tex
120-
await asyncio.sleep(2)
121+
await asyncio.sleep(self.SLEEP_SECONDS_AFTER_TIMEOUT)
121122
continue
122123
except AuthenticationException as auex:
123124
await self.close()
@@ -134,7 +135,7 @@ async def _query(self, request: Union[str, Dict], retry_count: int = 3) -> Dict:
134135
await self.close()
135136
_LOGGER.debug("Giving up on %s after %s retries", self.host, retry)
136137
raise ex
137-
await asyncio.sleep(2)
138+
await asyncio.sleep(self.SLEEP_SECONDS_AFTER_TIMEOUT)
138139
continue
139140
except Exception as ex:
140141
if retry >= retry_count:

0 commit comments

Comments
 (0)
0