From 3f802843941e9e0bc98909aa99fd0844e07e4303 Mon Sep 17 00:00:00 2001 From: David Bonnes Date: Sat, 2 Nov 2024 16:57:53 +0000 Subject: [PATCH] rename v1 exceptions --- src/evohomeasync/__init__.py | 18 ++++++++++-------- src/evohomeasync/auth.py | 10 +++++----- src/evohomeasync/exceptions.py | 16 ++++++++-------- src/evohomeasync2/exceptions.py | 2 +- tests/tests_rf/conftest.py | 4 ++-- 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/evohomeasync/__init__.py b/src/evohomeasync/__init__.py index ab54b26d..4280a65d 100644 --- a/src/evohomeasync/__init__.py +++ b/src/evohomeasync/__init__.py @@ -16,11 +16,11 @@ from . import exceptions as exc from .auth import Auth from .exceptions import ( # noqa: F401 - AuthenticationFailed, + AuthenticationFailedError, EvohomeError, - InvalidSchema, - RateLimitExceeded, - RequestFailed, + InvalidSchemaError, + RateLimitExceededError, + RequestFailedError, ) from .schema import ( SZ_ALLOWED_MODES, @@ -215,7 +215,7 @@ async def get_temperatures( # harden code against unexpected schema (JSON structure) except (LookupError, TypeError, ValueError) as err: - raise exc.InvalidSchema(str(err)) from err + raise exc.InvalidSchemaError(str(err)) from err return result # type: ignore[return-value] async def get_system_modes(self) -> NoReturn: @@ -280,12 +280,14 @@ async def _get_zone(self, id_or_name: _ZoneIdT | _ZoneNameT) -> _DeviceDictT: device_dict = self.named_devices.get(id_or_name) if device_dict is None: - raise exc.InvalidSchema( + raise exc.InvalidSchemaError( f"No zone {id_or_name} in location {self.location_id}" ) if (model := device_dict[SZ_THERMOSTAT_MODEL_TYPE]) != SZ_EMEA_ZONE: - raise exc.InvalidSchema(f"Zone {id_or_name} is not an EMEA_ZONE: {model}") + raise exc.InvalidSchemaError( + f"Zone {id_or_name} is not an EMEA_ZONE: {model}" + ) return device_dict @@ -352,7 +354,7 @@ async def _get_dhw(self) -> _DeviceDictT: ret: _DeviceDictT = device return ret - raise exc.InvalidSchema(f"No DHW in location {self.location_id}") + raise exc.InvalidSchemaError(f"No DHW in location {self.location_id}") async def _set_dhw( self, diff --git a/src/evohomeasync/auth.py b/src/evohomeasync/auth.py index 0705789c..75fd9147 100644 --- a/src/evohomeasync/auth.py +++ b/src/evohomeasync/auth.py @@ -198,16 +198,16 @@ async def make_request( except aiohttp.ClientResponseError as err: if response.method == HTTPMethod.POST: # POST only used when authenticating - raise exc.AuthenticationFailed( # includes TOO_MANY_REQUESTS + raise exc.AuthenticationFailedError( # includes TOO_MANY_REQUESTS str(err), status=err.status ) from err if response.status == HTTPStatus.TOO_MANY_REQUESTS: - raise exc.RateLimitExceeded(str(err), status=err.status) from err - raise exc.RequestFailed(str(err), status=err.status) from err + raise exc.RateLimitExceededError(str(err), status=err.status) from err + raise exc.RequestFailedError(str(err), status=err.status) from err except aiohttp.ClientError as err: # using response causes UnboundLocalError if method == HTTPMethod.POST: # POST only used when authenticating - raise exc.AuthenticationFailed(str(err)) from err - raise exc.RequestFailed(str(err)) from err + raise exc.AuthenticationFailedError(str(err)) from err + raise exc.RequestFailedError(str(err)) from err return response diff --git a/src/evohomeasync/exceptions.py b/src/evohomeasync/exceptions.py index 14ecbf53..f4a4a87f 100644 --- a/src/evohomeasync/exceptions.py +++ b/src/evohomeasync/exceptions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""evohomeasync provides an async client for the *original* Evohome TCC API.""" +"""evohomeasync provides an async client for the v1 Evohome TCC API.""" from __future__ import annotations @@ -16,15 +16,15 @@ class EvohomeError(EvohomeBaseError): """The base exception class for evohome-async.""" -class DeprecationError(EvohomeBaseError): - """The method or property has changed, or is otherwise deprecated.""" +class InvalidSchemaError(EvohomeError): + """The config/status JSON is invalid (e.g. missing an entity id).""" -class InvalidSchema(EvohomeError): - """The config/status JSON is invalid (e.g. missing an entity id).""" +class SystemConfigBaseError(EvohomeError): + """The system configuration is missing/invalid.""" -class RequestFailed(EvohomeError): +class RequestFailedError(EvohomeError): """The API request failed for some reason (no/invalid/unexpected response). Could be caused by any aiohttp.ClientError, for example: ConnectionError. If the @@ -36,11 +36,11 @@ def __init__(self, message: str, status: int | None = None) -> None: self.status = status # iff cause was aiohttp.ClientResponseError -class RateLimitExceeded(RequestFailed): +class RateLimitExceededError(RequestFailedError): """API request failed because the vendor's API rate limit was exceeded.""" -class AuthenticationFailed(RequestFailed): +class AuthenticationFailedError(RequestFailedError): """Unable to authenticate (unable to obtain an access token). The cause could be any FailedRequest, including RateLimitExceeded. diff --git a/src/evohomeasync2/exceptions.py b/src/evohomeasync2/exceptions.py index b120ccf7..ebf7034e 100644 --- a/src/evohomeasync2/exceptions.py +++ b/src/evohomeasync2/exceptions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python3 -"""evohomeasync2 provides an async client for the updated Evohome TCC API.""" +"""evohomeasync2 provides an async client for the v2 Evohome TCC API.""" from __future__ import annotations diff --git a/tests/tests_rf/conftest.py b/tests/tests_rf/conftest.py index 2fda6eb3..8f8f07d3 100644 --- a/tests/tests_rf/conftest.py +++ b/tests/tests_rf/conftest.py @@ -20,7 +20,7 @@ # # normally, we want debug flags to be False -_DBG_USE_REAL_AIOHTTP = False +_DBG_USE_REAL_AIOHTTP = True _DBG_DISABLE_STRICT_ASSERTS = False # of response content-type, schema if TYPE_CHECKING: @@ -139,7 +139,7 @@ async def evohome_v1( try: yield evo - except evo1.AuthenticationFailed as err: + except evo1.AuthenticationFailedError as err: if not _DBG_USE_REAL_AIOHTTP: raise pytest.skip(f"Unable to authenticate: {err}")