mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-08 16:38:01 +00:00
Add optional error code to exceptions (#585)
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
"""python-kasa exceptions."""
|
||||
from enum import IntEnum
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class SmartDeviceException(Exception):
|
||||
"""Base exception for device errors."""
|
||||
|
||||
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
|
||||
self.error_code = error_code
|
||||
super().__init__(args)
|
||||
|
||||
|
||||
class UnsupportedDeviceException(SmartDeviceException):
|
||||
"""Exception for trying to connect to unsupported devices."""
|
||||
@@ -17,14 +22,23 @@ class UnsupportedDeviceException(SmartDeviceException):
|
||||
class AuthenticationException(SmartDeviceException):
|
||||
"""Base exception for device authentication errors."""
|
||||
|
||||
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
|
||||
super().__init__(args, error_code)
|
||||
|
||||
|
||||
class RetryableException(SmartDeviceException):
|
||||
"""Retryable exception for device errors."""
|
||||
|
||||
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
|
||||
super().__init__(args, error_code)
|
||||
|
||||
|
||||
class TimeoutException(SmartDeviceException):
|
||||
"""Timeout exception for device errors."""
|
||||
|
||||
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
|
||||
super().__init__(args, error_code)
|
||||
|
||||
|
||||
class SmartErrorCode(IntEnum):
|
||||
"""Enum for SMART Error Codes."""
|
||||
|
Reference in New Issue
Block a user