Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PyViCare/PyViCareAbstractOAuthManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from PyViCare.PyViCareUtils import (PyViCareCommandError,
PyViCareDeviceCommunicationError,
PyViCareInternalServerError,
PyViCareNotPaidForError,
PyViCareRateLimitError)

logger = logging.getLogger('ViCare')
Expand Down Expand Up @@ -48,6 +49,7 @@ def get(self, url: str) -> Any:
self.__handle_expired_token(response)
self.__handle_rate_limit(response)
self.__handle_device_communication_error(response)
self.__handle_not_paid_for(response)
self.__handle_server_error(response)
return response
except TokenExpiredError:
Expand All @@ -72,6 +74,10 @@ def __handle_device_communication_error(self, response):
if ("errorType" in response and response["errorType"] == "DEVICE_COMMUNICATION_ERROR"):
raise PyViCareDeviceCommunicationError(response)

def __handle_not_paid_for(self, response):
if ("errorType" in response and response["errorType"] == "PACKAGE_NOT_PAID_FOR"):
raise PyViCareNotPaidForError(response)

def __handle_server_error(self, response):
if ("statusCode" in response and response["statusCode"] >= 500):
raise PyViCareInternalServerError(response)
Expand Down
7 changes: 7 additions & 0 deletions PyViCare/PyViCareCachedService.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from PyViCare.PyViCareUtils import (PyViCareDeviceCommunicationError,
PyViCareInvalidDataError,
PyViCareInternalServerError,
PyViCareNotPaidForError,
PyViCareNotSupportedFeatureError,
ViCareTimer)

logger = logging.getLogger('ViCare')
Expand Down Expand Up @@ -44,6 +46,11 @@ def __get_or_update_cache(self):

try:
data = self.fetch_all_features()
except PyViCareNotPaidForError as e:
logger.error("Viessmann API denied access (PACKAGE_NOT_PAID_FOR). Features unavailable: %s", e)
if self.__cache is not None:
return self.__cache
raise PyViCareNotSupportedFeatureError("PACKAGE_NOT_PAID_FOR")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we note in the exception which feature is unavailable, can you bring that in here somehow?

except (PyViCareDeviceCommunicationError, PyViCareInternalServerError) as e:
if self.__cache is not None:
logger.warning("API error, returning stale cache: %s", e)
Expand Down
11 changes: 11 additions & 0 deletions PyViCare/PyViCareUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ class PyViCareInvalidDataError(Exception):
pass


class PyViCareNotPaidForError(Exception):
def __init__(self, response):
extended_payload = response.get("extendedPayload", {})
monetization = extended_payload.get("monetization", "Unknown")

msg = f"Feature not available: {monetization}"

super().__init__(self, msg)
self.message = msg


class PyViCareDeviceCommunicationError(Exception):
def __init__(self, response):
extended_payload = response.get("extendedPayload", {})
Expand Down
Loading