mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-11-25 02:38:30 +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:
@@ -21,7 +21,7 @@ from voluptuous import (
|
||||
)
|
||||
|
||||
import kasa
|
||||
from kasa import Credentials, Device, DeviceConfig, SmartDeviceException
|
||||
from kasa import Credentials, Device, DeviceConfig, KasaException
|
||||
from kasa.exceptions import SmartErrorCode
|
||||
from kasa.iot import IotDevice
|
||||
from kasa.smart import SmartChildDevice, SmartDevice
|
||||
@@ -67,8 +67,8 @@ async def test_state_info(dev):
|
||||
@device_iot
|
||||
async def test_invalid_connection(dev):
|
||||
with patch.object(
|
||||
FakeIotProtocol, "query", side_effect=SmartDeviceException
|
||||
), pytest.raises(SmartDeviceException):
|
||||
FakeIotProtocol, "query", side_effect=KasaException
|
||||
), pytest.raises(KasaException):
|
||||
await dev.update()
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ async def test_initial_update_no_emeter(dev, mocker):
|
||||
|
||||
@device_iot
|
||||
async def test_query_helper(dev):
|
||||
with pytest.raises(SmartDeviceException):
|
||||
with pytest.raises(KasaException):
|
||||
await dev._query_helper("test", "testcmd", {})
|
||||
# TODO check for unwrapping?
|
||||
|
||||
@@ -328,7 +328,7 @@ async def test_update_no_device_info(dev: SmartDevice):
|
||||
}
|
||||
msg = f"get_device_info not found in {mock_response} for device 127.0.0.123"
|
||||
with patch.object(dev.protocol, "query", return_value=mock_response), pytest.raises(
|
||||
SmartDeviceException, match=msg
|
||||
KasaException, match=msg
|
||||
):
|
||||
await dev.update()
|
||||
|
||||
@@ -348,6 +348,16 @@ def test_deprecated_devices(device_class, use_class):
|
||||
getattr(module, use_class.__name__)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"exceptions_class, use_class", kasa.deprecated_exceptions.items()
|
||||
)
|
||||
def test_deprecated_exceptions(exceptions_class, use_class):
|
||||
msg = f"{exceptions_class} is deprecated, use {use_class.__name__} instead"
|
||||
with pytest.deprecated_call(match=msg):
|
||||
getattr(kasa, exceptions_class)
|
||||
getattr(kasa, use_class.__name__)
|
||||
|
||||
|
||||
def check_mac(x):
|
||||
if re.match("[0-9a-f]{2}([-:])[0-9a-f]{2}(\\1[0-9a-f]{2}){4}$", x.lower()):
|
||||
return x
|
||||
|
||||
Reference in New Issue
Block a user