Skip to content

Commit

Permalink
correcting use off access Token
Browse files Browse the repository at this point in the history
  • Loading branch information
JurgenLB authored Nov 18, 2024
1 parent 16c2d20 commit 6073c26
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lnetatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Multiple contributors : see https://github.com/philippelt/netatmo-api-python
# License : GPL V3
"""
This API provides access to the Netatmo weather station or/and the Welcome camera
This API provides access to the Netatmo weather station or/and other installed devices
This package can be used with Python2 or Python3 applications and do not
require anything else than standard libraries
Expand Down Expand Up @@ -210,12 +210,14 @@ class ClientAuth:

def __init__(self, clientId=None,
clientSecret=None,
accessToken=None,
refreshToken=None,
credentialFile=None):

# replace values with content of env variables if defined
clientId = getenv("CLIENT_ID", clientId)
clientSecret = getenv("CLIENT_SECRET", clientSecret)
accessToken = getenv("ACCESS_TOKEN", accessToken)
refreshToken = getenv("REFRESH_TOKEN", refreshToken)

# Look for credentials in file if not already provided
Expand All @@ -232,9 +234,9 @@ def __init__(self, clientId=None,

self._clientId = clientId or cred["CLIENT_ID"]
self._clientSecret = clientSecret or cred["CLIENT_SECRET"]
self._accessToken = accessToken or cred["ACCESS_TOKEN"] # Will be refreshed before any use
self.refreshToken = refreshToken or cred["REFRESH_TOKEN"]
self.expiration = 0 # Force refresh token
self._accessToken = None # Will be refreshed before any use

@property
def accessToken(self):
Expand All @@ -253,6 +255,7 @@ def renew_token(self):
self.refreshToken = resp['refresh_token']
cred = {"CLIENT_ID":self._clientId,
"CLIENT_SECRET":self._clientSecret,
"ACCESS_TOKEN" : self._accessToken,
"REFRESH_TOKEN":self.refreshToken }
if self._credentialFile:
with open(self._credentialFile, "w", encoding="utf-8") as f:
Expand Down Expand Up @@ -1007,16 +1010,16 @@ def __init__(self, authData):
# homecoach data
if not self.rawData : raise NoDevice("No HomeCoach available")

def HomecoachDevice(self, id=""):
def HomecoachDevice(self, hid=""):
for device in self.rawData:
if id == device['_id']:
if hid == device['_id']:
return device
return None

def Dashboard(self, id=""):
def Dashboard(self, hid=""):
#D = self.HomecoachDevice['dashboard_data']
for device in self.rawData:
if id == device['_id']:
if hid == device['_id']:
D = device['dashboard_data']
return D

Expand Down

0 comments on commit 6073c26

Please sign in to comment.