Skip to content

Commit

Permalink
Shift error handling code to make homeassistant update compatible (#1129
Browse files Browse the repository at this point in the history
)

* Shift error handling code to make homeassistant update compatible

* Update version to 6.1.3
  • Loading branch information
allenporter authored Oct 21, 2024
1 parent be7a006 commit 5d0f712
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
8 changes: 4 additions & 4 deletions google_nest_sdm/admin_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ def __init__(
async def create_topic(self, topic_name: str) -> None:
"""Create a pubsub topic for the project."""
validate_topic_name(topic_name)
await self._auth.request("put", topic_name)
await self._auth.put(topic_name)

async def delete_topic(self, topic_name: str) -> None:
"""Delete a pubsub topic for the project."""
validate_topic_name(topic_name)
await self._auth.request("delete", topic_name)
await self._auth.delete(topic_name)

async def list_topics(self, projects_prefix: str) -> list[str]:
"""List the pubsub topics for the project.
Expand All @@ -152,12 +152,12 @@ async def create_subscription(
validate_topic_name(topic_name)
validate_subscription_name(subscription_name)
body = {"topic": topic_name}
await self._auth.request("put", subscription_name, json=body)
await self._auth.put(subscription_name, json=body)

async def delete_subscription(self, subscription_name: str) -> None:
"""Delete a pubsub subscription for the project."""
validate_subscription_name(subscription_name)
await self._auth.request("delete", subscription_name)
await self._auth.delete(subscription_name)

async def list_subscriptions(self, projects_prefix: str) -> list[dict[str, Any]]:
"""List the pubsub subscriptions for the project.
Expand Down
20 changes: 15 additions & 5 deletions google_nest_sdm/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,12 @@ async def request(
async def _request(
self, method: str, url: str, headers: dict[str, str], **kwargs: Any
) -> aiohttp.ClientResponse:
response = await self._websession.request(method, url, **kwargs, headers=headers)
return await AbstractAuth._raise_for_status(response)

return await self._websession.request(method, url, **kwargs, headers=headers)

async def get(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
"""Make a get request."""
return await self.request("get", url, **kwargs)
response = await self.request("get", url, **kwargs)
return await AbstractAuth._raise_for_status(response)

async def get_json(self, url: str, **kwargs: Any) -> dict[str, Any]:
"""Make a get request and return json response."""
Expand All @@ -167,7 +166,8 @@ async def get_json(self, url: str, **kwargs: Any) -> dict[str, Any]:

async def post(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
"""Make a post request."""
return await self.request("post", url, **kwargs)
response = await self.request("post", url, **kwargs)
return await AbstractAuth._raise_for_status(response)

async def post_json(self, url: str, **kwargs: Any) -> dict[str, Any]:
"""Make a post request and return a json response."""
Expand All @@ -181,6 +181,16 @@ async def post_json(self, url: str, **kwargs: Any) -> dict[str, Any]:
_LOGGER.debug("response=%s", result)
return result

async def put(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
"""Make a put request."""
response = await self.request("put", url, **kwargs)
return await AbstractAuth._raise_for_status(response)

async def delete(self, url: str, **kwargs: Any) -> aiohttp.ClientResponse:
"""Make a delete request."""
response = await self.request("delete", url, **kwargs)
return await AbstractAuth._raise_for_status(response)

@classmethod
async def _raise_for_status(
cls, resp: aiohttp.ClientResponse
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = google_nest_sdm
version = 6.1.2
version = 6.1.3
description = Library for the Google Nest SDM API
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 5d0f712

Please sign in to comment.