Skip to content

Commit

Permalink
Prepared for Home Assistant PR as 0.2.1
Browse files Browse the repository at this point in the history
- Added additional exception handling
  • Loading branch information
G-Two committed May 17, 2020
1 parent 9f6f026 commit eff2a0d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion subarulink/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
For more details about this api, please refer to the documentation at
https://github.com/G-Two/subarulink
"""
__version__ = "0.2.0"
__version__ = "0.2.1"
6 changes: 4 additions & 2 deletions subarulink/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ async def __open(
js_resp = await resp.json()
_LOGGER.debug(pprint.pformat(js_resp))
raise SubaruException(resp.status)
except aiohttp.ClientResponseError as exception_:
raise SubaruException(exception_.status)
except aiohttp.ClientResponseError as exception:
raise SubaruException(exception.status)
except aiohttp.ClientConnectionError:
raise SubaruException("aiohttp.ClientConnectionError")
return resp
4 changes: 3 additions & 1 deletion subarulink/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from subarulink.connection import Connection
import subarulink.const as sc
from subarulink.exceptions import SubaruException
from subarulink.exceptions import InvalidPIN, SubaruException

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -298,6 +298,8 @@ async def _remote_command(
req_id = js_resp["data"][sc.SERVICE_REQ_ID]
js_resp = await self._wait_request_status(req_id, api_gen, poll_url)
return js_resp
elif js_resp["errorCode"] == "InvalidCredentials":
raise InvalidPIN(js_resp["data"]["errorDescription"])
raise SubaruException("Remote command failed. Response: %s " % js_resp)

async def _actuate(self, vin, cmd, data=None):
Expand Down
13 changes: 11 additions & 2 deletions subarulink/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ def __init__(self, message, *args, **kwargs):
super().__init__(*args, **kwargs)


class InvalidPIN(SubaruException):
"""Class of exceptions for invalid PIN number."""

def __init__(self, *args, **kwargs):
# pylint: disable=super-init-not-called
"""Initialize exception."""
pass


class RetryLimitError(SubaruException):
"""Class of exceptions for hitting retry limits."""

def __init__(self, *args, **kwargs):
# pylint: disable=super-init-not-called
"""Initialize exceptions for the Subaru retry limit API."""
"""Initialize exception."""
pass


Expand All @@ -32,5 +41,5 @@ class IncompleteCredentials(SubaruException):

def __init__(self, *args, **kwargs):
# pylint: disable=super-init-not-called
"""Initialize exceptions for the Subaru retry limit API."""
"""Initialize exception."""
pass

0 comments on commit eff2a0d

Please # to comment.