From c964c110e8f7ebe3aefa8178fd2230e31afd1f89 Mon Sep 17 00:00:00 2001 From: grm Date: Thu, 8 Jul 2021 18:26:49 +0200 Subject: [PATCH] take advantage of new py-smart-gardena to have authentication exception logs --- .../gardena_smart_system/__init__.py | 33 +++++++++++-------- .../gardena_smart_system/manifest.json | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/custom_components/gardena_smart_system/__init__.py b/custom_components/gardena_smart_system/__init__.py index bf52143..d2ae683 100644 --- a/custom_components/gardena_smart_system/__init__.py +++ b/custom_components/gardena_smart_system/__init__.py @@ -2,6 +2,8 @@ import logging from gardena.smart_system import SmartSystem +from gardena.exceptions.authentication_exception import AuthenticationException + from oauthlib.oauth2.rfc6749.errors import ( AccessDeniedError, InvalidClientError, @@ -84,20 +86,23 @@ def __init__(self, hass, *, email, password, client_id, smart_system=SmartSystem def start(self): _LOGGER.debug("Starting GardenaSmartSystem") - self.smart_system.authenticate() - self.smart_system.update_locations() - - if len(self.smart_system.locations) < 1: - _LOGGER.error("No locations found") - raise Exception("No locations found") - - # currently gardena supports only one location and gateway, so we can take the first - location = list(self.smart_system.locations.values())[0] - _LOGGER.debug(f"Using location: {location.name} ({location.id})") - self.smart_system.update_devices(location) - self._hass.data[DOMAIN][GARDENA_LOCATION] = location - _LOGGER.debug("Starting GardenaSmartSystem websocket") - self.smart_system.start_ws(self._hass.data[DOMAIN][GARDENA_LOCATION]) + try: + self.smart_system.authenticate() + self.smart_system.update_locations() + + if len(self.smart_system.locations) < 1: + _LOGGER.error("No locations found") + raise Exception("No locations found") + + # currently gardena supports only one location and gateway, so we can take the first + location = list(self.smart_system.locations.values())[0] + _LOGGER.debug(f"Using location: {location.name} ({location.id})") + self.smart_system.update_devices(location) + self._hass.data[DOMAIN][GARDENA_LOCATION] = location + _LOGGER.debug("Starting GardenaSmartSystem websocket") + self.smart_system.start_ws(self._hass.data[DOMAIN][GARDENA_LOCATION]) + except AuthenticationException as ex: + _LOGGER.error(f"Authentication failed : {ex.message}. You may need to dcheck your token or create a new app in the gardena api and use the new token.") def stop(self): _LOGGER.debug("Stopping GardenaSmartSystem") diff --git a/custom_components/gardena_smart_system/manifest.json b/custom_components/gardena_smart_system/manifest.json index 77a1b6f..1eb76bf 100644 --- a/custom_components/gardena_smart_system/manifest.json +++ b/custom_components/gardena_smart_system/manifest.json @@ -7,5 +7,5 @@ "issue_tracker": "https://github.com/py-smart-gardena/hass-gardena-smart-system/issues", "dependencies": [], "codeowners": ["@py-smart-gardena"], - "requirements": ["py-smart-gardena==0.8.0"] + "requirements": ["py-smart-gardena==0.8.1"] }