@@ -120,6 +120,25 @@ def getParameter(key, default):
120120# Not working yet
121121#_CAM_FTP_ACTIVE = "/command/ftp_set_config?config=on_off:%s" # "on"|"off"
122122
123+ # UNITS used by Netatmo services
124+ UNITS = {
125+ "unit" : {
126+ 0 : "metric" ,
127+ 1 : "imperial"
128+ },
129+ "windunit" : {
130+ 0 : "kph" ,
131+ 1 : "mph" ,
132+ 2 : "ms" ,
133+ 3 : "beaufort" ,
134+ 4 : "knot"
135+ },
136+ "pressureunit" : {
137+ 0 : "mbar" ,
138+ 1 : "inHg" ,
139+ 2 : "mmHg"
140+ }
141+ }
123142
124143# Logger context
125144logger = logging .getLogger ("lnetatmo" )
@@ -198,6 +217,8 @@ class User:
198217 Args:
199218 authData (ClientAuth): Authentication information with a working access Token
200219 """
220+ warnings .warn ("The 'User' class is no longer maintained by Netatmo" ,
221+ DeprecationWarning )
201222 def __init__ (self , authData ):
202223 postParams = {
203224 "access_token" : authData .accessToken
@@ -208,6 +229,14 @@ def __init__(self, authData):
208229 self .ownerMail = self .rawData ['user' ]['mail' ]
209230
210231
232+ class UserInfo :
233+ """
234+ This class is populated with data from various Netatmo requests to provide
235+ complimentary data (eg Units for Weatherdata)
236+ """
237+ pass
238+
239+
211240class ThermostatData :
212241 """
213242 List the Thermostat and temperature modules
@@ -269,6 +298,7 @@ def __init__(self, authData):
269298 }
270299 resp = postRequest (_GETSTATIONDATA_REQ , postParams )
271300 self .rawData = resp ['body' ]['devices' ]
301+ # Weather data
272302 if not self .rawData : raise NoDevice ("No weather station available" )
273303 self .stations = { d ['_id' ] : d for d in self .rawData }
274304 self .modules = dict ()
@@ -278,6 +308,16 @@ def __init__(self, authData):
278308 for m in self .rawData [i ]['modules' ]:
279309 self .modules [ m ['_id' ] ] = m
280310 self .default_station = list (self .stations .values ())[0 ]['station_name' ]
311+ # User data
312+ userData = resp ['body' ]['user' ]
313+ self .user = UserInfo ()
314+ setattr (self .user , "mail" , userData ['mail' ])
315+ for k ,v in userData ['administrative' ].items ():
316+ if k in UNITS :
317+ setattr (self .user , k , UNITS [k ][v ])
318+ else :
319+ setattr (self .user , k , v )
320+
281321
282322 def modulesNamesList (self , station = None ):
283323 res = [m ['module_name' ] for m in self .modules .values ()]
0 commit comments