Skip to content

Commit

Permalink
cloudapi: api_request: process 422 response
Browse files Browse the repository at this point in the history
The 422 response is given when a device is disconnected from the Cloud API.

Signed-off-by: Álvaro Fernández Rojas <noltari@gmail.com>
  • Loading branch information
Noltari committed Oct 7, 2024
1 parent 15b1848 commit 39cb59d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions aioairzone_cloud/cloudapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
LoginError,
TokenRefreshError,
TooManyRequests,
UnprocessableEntity,
)
from .group import Group
from .hotwater import HotWater
Expand Down Expand Up @@ -167,6 +168,8 @@ async def api_request(
raise APIError(err) from err
if err.status == 401:
raise AuthError(err) from err
if err.status == 422:
raise UnprocessableEntity(err) from err
if err.status == 429:
raise TooManyRequests(err) from err

Expand Down Expand Up @@ -197,10 +200,14 @@ async def api_get_device_config(self, device: Device) -> dict[str, Any]:
}
dev_params = urllib.parse.urlencode(params)

res = await self.api_request(
"GET",
f"{API_V1}/{API_DEVICES}/{url_id}/{API_CONFIG}?{dev_params}",
)
try:
res = await self.api_request(
"GET",
f"{API_V1}/{API_DEVICES}/{url_id}/{API_CONFIG}?{dev_params}",
)
except UnprocessableEntity:
res = {}

await self.set_api_raw_data(RAW_DEVICES_CONFIG, dev_id, res)

return res
Expand Down
4 changes: 4 additions & 0 deletions aioairzone_cloud/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ class ParamUpdateFailure(AirzoneCloudError):

class TooManyRequests(AirzoneCloudError):
"""Exception raised when max API requests are exceeded."""


class UnprocessableEntity(AirzoneCloudError):
"""Exception raised when device is disconnected."""

0 comments on commit 39cb59d

Please sign in to comment.