mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-07 11:14:02 +00:00
Rename and deprecate exception classes (#739)
# Public # SmartDeviceException -> KasaException UnsupportedDeviceException(SmartDeviceException) -> UnsupportedDeviceError(KasaException) TimeoutException(SmartDeviceException, asyncio.TimeoutError) -> TimeoutError(KasaException, asyncio.TimeoutError) Add new exception for error codes -> DeviceError(KasaException) AuthenticationException(SmartDeviceException) -> AuthenticationError(DeviceError) # Internal # RetryableException(SmartDeviceException) -> _RetryableError(DeviceError) ConnectionException(SmartDeviceException) -> _ConnectionError(KasaException)
This commit is contained in:
@@ -9,7 +9,7 @@ from ..device import Device, WifiNetwork
|
||||
from ..device_type import DeviceType
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..emeterstatus import EmeterStatus
|
||||
from ..exceptions import AuthenticationException, SmartDeviceException, SmartErrorCode
|
||||
from ..exceptions import AuthenticationError, DeviceError, KasaException, SmartErrorCode
|
||||
from ..feature import Feature, FeatureType
|
||||
from ..smartprotocol import SmartProtocol
|
||||
from .modules import ( # noqa: F401
|
||||
@@ -85,7 +85,7 @@ class SmartDevice(Device):
|
||||
return response
|
||||
if default is not None:
|
||||
return default
|
||||
raise SmartDeviceException(
|
||||
raise KasaException(
|
||||
f"{request} not found in {responses} for device {self.host}"
|
||||
)
|
||||
|
||||
@@ -100,7 +100,7 @@ class SmartDevice(Device):
|
||||
async def update(self, update_children: bool = True):
|
||||
"""Update the device."""
|
||||
if self.credentials is None and self.credentials_hash is None:
|
||||
raise AuthenticationException("Tapo plug requires authentication.")
|
||||
raise AuthenticationError("Tapo plug requires authentication.")
|
||||
|
||||
if self._components_raw is None:
|
||||
await self._negotiate()
|
||||
@@ -341,7 +341,7 @@ class SmartDevice(Device):
|
||||
"""Retrieve current energy readings."""
|
||||
_LOGGER.warning("Deprecated, use `emeter_realtime`.")
|
||||
if not self.has_emeter:
|
||||
raise SmartDeviceException("Device has no emeter")
|
||||
raise KasaException("Device has no emeter")
|
||||
return self.emeter_realtime
|
||||
|
||||
@property
|
||||
@@ -421,7 +421,7 @@ class SmartDevice(Device):
|
||||
after some delay.
|
||||
"""
|
||||
if not self.credentials:
|
||||
raise AuthenticationException("Device requires authentication.")
|
||||
raise AuthenticationError("Device requires authentication.")
|
||||
|
||||
payload = {
|
||||
"account": {
|
||||
@@ -445,10 +445,9 @@ class SmartDevice(Device):
|
||||
# Thus, We limit retries and suppress the raised exception as useless.
|
||||
try:
|
||||
return await self.protocol.query({"set_qs_info": payload}, retry_count=0)
|
||||
except SmartDeviceException as ex:
|
||||
if ex.error_code: # Re-raise on device-reported errors
|
||||
raise
|
||||
|
||||
except DeviceError:
|
||||
raise # Re-raise on device-reported errors
|
||||
except KasaException:
|
||||
_LOGGER.debug("Received an expected for wifi join, but this is expected")
|
||||
|
||||
async def update_credentials(self, username: str, password: str):
|
||||
|
Reference in New Issue
Block a user