Skip to content

Commit

Permalink
Merge pull request #38 from sander76/3.1.1
Browse files Browse the repository at this point in the history
3.1.1
  • Loading branch information
kingy444 authored Mar 22, 2024
2 parents d9b3cc8 + 12c7e8a commit f5d54d0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,7 @@ Changelog
- Update error handling in tools
- Handle empty values and zeros better
- Add type 53 (Sonnette) and yype 95 (Aura Illuminated, Roller). Note: *Type 95 do not support light control*
- Handle PowerType 11 + 12. Both are fixed and cannot be edited
- Handle PowerType 11 + 12. Both are fixed and cannot be edited

**v3.1.1**
- Fix missed timeout blocks and handle in websession
2 changes: 1 addition & 1 deletion aiopvapi/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Aio PowerView api version."""

__version__ = "3.1.0"
__version__ = "3.1.1"
41 changes: 23 additions & 18 deletions aiopvapi/helpers/aiorequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ async def get(self, url: str, params: str = None, suppress_timeout: bool = False
"""
response = None
try:
_LOGGER.debug("Sending GET request to: %s params: %s kwargs: %s", url, params, kwargs)
async with asyncio.timeout(self._timeout):
response = await self.websession.get(url, params=params, **kwargs)
return await self.check_response(response, [200, 204])
timeout = kwargs.pop("timeout", None) or self._timeout
_LOGGER.debug("Sending GET request to: %s params: %s timeout: %s kwargs: %s", url, params, timeout, kwargs)
response = await self.websession.get(url, params=params, timeout=timeout, **kwargs)
return await self.check_response(response, [200, 204])
except TimeoutError as error:
if suppress_timeout:
_LOGGER.debug("Timeout occurred but was suppressed: %s", error)
Expand All @@ -130,10 +130,10 @@ async def post(self, url: str, data: dict = None, suppress_timeout: bool = False
"""
response = None
try:
_LOGGER.debug("Sending POST request to: %s data: %s kwargs: %s", url, data, kwargs)
async with asyncio.timeout(self._timeout):
response = await self.websession.post(url, json=data, **kwargs)
return await self.check_response(response, [200, 201])
timeout = kwargs.pop("timeout", None) or self._timeout
_LOGGER.debug("Sending POST request to: %s data: %s timeout: %s kwargs: %s", url, data, timeout, kwargs)
response = await self.websession.post(url,json=data,timeout=timeout,**kwargs)
return await self.check_response(response, [200, 201])
except TimeoutError as error:
if suppress_timeout:
_LOGGER.debug("Timeout occurred but was suppressed: %s", error)
Expand All @@ -159,10 +159,10 @@ async def put(self, url: str, data: dict = None, params=None, suppress_timeout:
"""
response = None
try:
_LOGGER.debug("Sending PUT request to: %s params: %s data: %s kwargs: %s", url, params, data, kwargs)
async with asyncio.timeout(self._timeout):
response = await self.websession.put(url, json=data, params=params, **kwargs)
return await self.check_response(response, [200, 204])
timeout = kwargs.pop("timeout", None) or self._timeout
_LOGGER.debug("Sending PUT request to: %s params: %s data: %s timeout: %s kwargs: %s", url, params, data, timeout, kwargs)
response = await self.websession.put(url, json=data, params=params, timeout=timeout, **kwargs)
return await self.check_response(response, [200, 204])
except TimeoutError as error:
if suppress_timeout:
_LOGGER.debug("Timeout occurred but was suppressed: %s", error)
Expand All @@ -174,7 +174,7 @@ async def put(self, url: str, data: dict = None, params=None, suppress_timeout:
if response is not None:
await response.release()

async def delete(self, url: str, params: dict = None):
async def delete(self, url: str, params: dict = None, suppress_timeout: bool = False, **kwargs):
"""Delete a resource.
:param url: Endpoint
Expand All @@ -185,11 +185,16 @@ async def delete(self, url: str, params: dict = None):
"""
response = None
try:
_LOGGER.debug("Sending DELETE request to: %s with param %s", url, params)
async with asyncio.timeout(self._timeout):
response = await self.websession.delete(url, params=params)
return await self.check_response(response, [200, 204])
except (TimeoutError, aiohttp.ClientError) as error:
timeout = kwargs.pop("timeout", None) or self._timeout
_LOGGER.debug("Sending DELETE request to: %s params: %s timeout: %s kwargs: %s",url,params,timeout, kwargs)
response = await self.websession.delete(url, params=params, timeout=timeout, **kwargs)
return await self.check_response(response, [200, 204])
except TimeoutError as error:
if suppress_timeout:
_LOGGER.debug("Timeout occurred but was suppressed: %s", error)
return None
raise PvApiConnectionError("Timeout in communicating with PowerView Hub") from error
except aiohttp.ClientError as error:
raise PvApiConnectionError("Failed to communicate with PowerView Hub") from error
finally:
if response is not None:
Expand Down
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ Shades not listed will get their features from their **capabilities**, unfortuna
- Add type 53 (Sonnette) and yype 95 (Aura Illuminated, Roller). Note: *Type 95 do not support light control*
- Handle PowerType 11 + 12. Both are fixed and cannot be edited

### v3.1.1
- Fix missed timeout blocks and handle in websession

## Links

---
Expand Down

0 comments on commit f5d54d0

Please sign in to comment.