3
3
# Multiple contributors : see https://github.com/philippelt/netatmo-api-python
4
4
# License : GPL V3
5
5
"""
6
- This API provides access to the Netatmo weather station or/and the Welcome camera
6
+ This API provides access to the Netatmo weather station or/and other installed devices
7
7
This package can be used with Python2 or Python3 applications and do not
8
8
require anything else than standard libraries
9
9
@@ -210,12 +210,14 @@ class ClientAuth:
210
210
211
211
def __init__ (self , clientId = None ,
212
212
clientSecret = None ,
213
+ accessToken = None ,
213
214
refreshToken = None ,
214
215
credentialFile = None ):
215
216
216
217
# replace values with content of env variables if defined
217
218
clientId = getenv ("CLIENT_ID" , clientId )
218
219
clientSecret = getenv ("CLIENT_SECRET" , clientSecret )
220
+ accessToken = getenv ("ACCESS_TOKEN" , accessToken )
219
221
refreshToken = getenv ("REFRESH_TOKEN" , refreshToken )
220
222
221
223
# Look for credentials in file if not already provided
@@ -232,9 +234,9 @@ def __init__(self, clientId=None,
232
234
233
235
self ._clientId = clientId or cred ["CLIENT_ID" ]
234
236
self ._clientSecret = clientSecret or cred ["CLIENT_SECRET" ]
237
+ self ._accessToken = accessToken or cred ["ACCESS_TOKEN" ] # Will be refreshed before any use
235
238
self .refreshToken = refreshToken or cred ["REFRESH_TOKEN" ]
236
239
self .expiration = 0 # Force refresh token
237
- self ._accessToken = None # Will be refreshed before any use
238
240
239
241
@property
240
242
def accessToken (self ):
@@ -253,6 +255,7 @@ def renew_token(self):
253
255
self .refreshToken = resp ['refresh_token' ]
254
256
cred = {"CLIENT_ID" :self ._clientId ,
255
257
"CLIENT_SECRET" :self ._clientSecret ,
258
+ "ACCESS_TOKEN" : self ._accessToken ,
256
259
"REFRESH_TOKEN" :self .refreshToken }
257
260
if self ._credentialFile :
258
261
with open (self ._credentialFile , "w" , encoding = "utf-8" ) as f :
@@ -1007,16 +1010,16 @@ def __init__(self, authData):
1007
1010
# homecoach data
1008
1011
if not self .rawData : raise NoDevice ("No HomeCoach available" )
1009
1012
1010
- def HomecoachDevice (self , id = "" ):
1013
+ def HomecoachDevice (self , hid = "" ):
1011
1014
for device in self .rawData :
1012
- if id == device ['_id' ]:
1015
+ if hid == device ['_id' ]:
1013
1016
return device
1014
1017
return None
1015
1018
1016
- def Dashboard (self , id = "" ):
1019
+ def Dashboard (self , hid = "" ):
1017
1020
#D = self.HomecoachDevice['dashboard_data']
1018
1021
for device in self .rawData :
1019
- if id == device ['_id' ]:
1022
+ if hid == device ['_id' ]:
1020
1023
D = device ['dashboard_data' ]
1021
1024
return D
1022
1025
0 commit comments