Skip to content

Commit

Permalink
take advantage of new py-smart-gardena to have authentication excepti…
Browse files Browse the repository at this point in the history
…on logs
  • Loading branch information
grm committed Jul 8, 2021
1 parent cfae3de commit c964c11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
33 changes: 19 additions & 14 deletions custom_components/gardena_smart_system/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/gardena_smart_system/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}

0 comments on commit c964c11

Please sign in to comment.