Skip to content

Commit

Permalink
rename v1 exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Nov 2, 2024
1 parent 53d5965 commit 3f80284
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
18 changes: 10 additions & 8 deletions src/evohomeasync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/evohomeasync/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 8 additions & 8 deletions src/evohomeasync/exceptions.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/evohomeasync2/exceptions.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/tests_rf/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}")
Expand Down

0 comments on commit 3f80284

Please sign in to comment.