Cleanup custom exception kwarg handling (#602)

* Cleanup custom exceptions

* Read custom keyword arguments from kwargs
* Pass all input args to the super

Earlier behavior:
Got error: AuthenticationException((('Error logging in: 192.168.xx.xx: LOGIN_ERROR(-1501)',), <SmartErrorCode.LOGIN_ERROR: -1501>))

New behavior:
Got error: AuthenticationException('Error logging in: 192.168.xx.xx: LOGIN_ERROR(-1501)')

* Pass UnsupportedDeviceException kwargs to parent, too
This commit is contained in:
Teemu R 2024-01-02 16:24:09 +01:00 committed by GitHub
parent 7646bc4542
commit 5dafc1d1ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,39 +6,29 @@ from typing import Optional
class SmartDeviceException(Exception): class SmartDeviceException(Exception):
"""Base exception for device errors.""" """Base exception for device errors."""
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None): def __init__(self, *args, **kwargs):
self.error_code = error_code self.error_code: Optional["SmartErrorCode"] = kwargs.get("error_code", None)
super().__init__(args) super().__init__(*args)
class UnsupportedDeviceException(SmartDeviceException): class UnsupportedDeviceException(SmartDeviceException):
"""Exception for trying to connect to unsupported devices.""" """Exception for trying to connect to unsupported devices."""
def __init__(self, *args, discovery_result=None): def __init__(self, *args, **kwargs):
self.discovery_result = discovery_result self.discovery_result = kwargs.get("discovery_result")
super().__init__(args) super().__init__(*args, **kwargs)
class AuthenticationException(SmartDeviceException): class AuthenticationException(SmartDeviceException):
"""Base exception for device authentication errors.""" """Base exception for device authentication errors."""
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
super().__init__(args, error_code)
class RetryableException(SmartDeviceException): class RetryableException(SmartDeviceException):
"""Retryable exception for device errors.""" """Retryable exception for device errors."""
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
super().__init__(args, error_code)
class TimeoutException(SmartDeviceException): class TimeoutException(SmartDeviceException):
"""Timeout exception for device errors.""" """Timeout exception for device errors."""
def __init__(self, *args, error_code: Optional["SmartErrorCode"] = None):
super().__init__(args, error_code)
class SmartErrorCode(IntEnum): class SmartErrorCode(IntEnum):
"""Enum for SMART Error Codes.""" """Enum for SMART Error Codes."""