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:
Steven B
2024-02-21 15:52:55 +00:00
committed by GitHub
parent 4beff228c9
commit 8c39e81a40
44 changed files with 393 additions and 361 deletions

View File

@@ -6,12 +6,13 @@ import pytest
from asyncclick.testing import CliRunner
from kasa import (
AuthenticationException,
AuthenticationError,
Credentials,
Device,
DeviceError,
EmeterStatus,
SmartDeviceException,
UnsupportedDeviceException,
KasaException,
UnsupportedDeviceError,
)
from kasa.cli import (
TYPE_TO_CLASS,
@@ -188,15 +189,13 @@ async def test_wifi_join_no_creds(dev):
)
assert res.exit_code != 0
assert isinstance(res.exception, AuthenticationException)
assert isinstance(res.exception, AuthenticationError)
@device_smart
async def test_wifi_join_exception(dev, mocker):
runner = CliRunner()
mocker.patch.object(
dev.protocol, "query", side_effect=SmartDeviceException(error_code=9999)
)
mocker.patch.object(dev.protocol, "query", side_effect=DeviceError(error_code=9999))
res = await runner.invoke(
wifi,
["join", "FOOBAR", "--keytype", "wpa_psk", "--password", "foobar"],
@@ -204,7 +203,7 @@ async def test_wifi_join_exception(dev, mocker):
)
assert res.exit_code != 0
assert isinstance(res.exception, SmartDeviceException)
assert isinstance(res.exception, KasaException)
@device_smart
@@ -509,7 +508,7 @@ async def test_host_unsupported(unsupported_device_info):
)
assert res.exit_code != 0
assert isinstance(res.exception, UnsupportedDeviceException)
assert isinstance(res.exception, UnsupportedDeviceError)
@new_discovery
@@ -522,7 +521,7 @@ async def test_discover_auth_failed(discovery_mock, mocker):
mocker.patch.object(
device_class,
"update",
side_effect=AuthenticationException("Failed to authenticate"),
side_effect=AuthenticationError("Failed to authenticate"),
)
res = await runner.invoke(
cli,
@@ -553,7 +552,7 @@ async def test_host_auth_failed(discovery_mock, mocker):
mocker.patch.object(
device_class,
"update",
side_effect=AuthenticationException("Failed to authenticate"),
side_effect=AuthenticationError("Failed to authenticate"),
)
res = await runner.invoke(
cli,
@@ -569,7 +568,7 @@ async def test_host_auth_failed(discovery_mock, mocker):
)
assert res.exit_code != 0
assert isinstance(res.exception, AuthenticationException)
assert isinstance(res.exception, AuthenticationError)
@pytest.mark.parametrize("device_type", list(TYPE_TO_CLASS))
@@ -616,7 +615,7 @@ async def test_shell(dev: Device, mocker):
async def test_errors(mocker):
runner = CliRunner()
err = SmartDeviceException("Foobar")
err = KasaException("Foobar")
# Test masking
mocker.patch("kasa.Discover.discover", side_effect=err)