Skip to content

Commit 8b418ea

Browse files
committed
[Change] Added UserInfo class to get units for weatherdata info
1 parent 746ecaa commit 8b418ea

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

lnetatmo.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
125144
logger = 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+
211240
class 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()]

samples/printAllLastData

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ import time
1313
import lnetatmo
1414

1515
authorization = lnetatmo.ClientAuth()
16-
devList = lnetatmo.WeatherStationData(authorization)
16+
weather = lnetatmo.WeatherStationData(authorization)
17+
18+
user = weather.user
19+
20+
print("Station owner : ", user.mail)
21+
print("Data units : ", user.unit)
22+
23+
print()
1724

1825
# For each available module in the returned data that should not be older than one hour (3600 s) from now
19-
for module, moduleData in devList.lastData(exclude=3600).items() :
26+
for module, moduleData in weather.lastData(exclude=3600).items() :
2027

2128
# Name of the module (or station embedded module), the name you defined in the web netatmo account station management
2229
print(module)
@@ -32,6 +39,10 @@ for module, moduleData in devList.lastData(exclude=3600).items() :
3239
#
3340
# $ printAllLastData
3441
#
42+
#Station owner : ph.larduinat@wanadoo.fr
43+
#Data units : metric
44+
#
45+
#
3546
#Office
3647
# AbsolutePressure : 988.7
3748
# CO2 : 726

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='lnetatmo',
7-
version='1.5.1',
7+
version='1.6.0',
88
classifiers=[
99
'Development Status :: 5 - Production/Stable',
1010
'Intended Audience :: Developers',
@@ -17,7 +17,7 @@
1717
scripts=[],
1818
data_files=[],
1919
url='https://github.com/philippelt/netatmo-api-python',
20-
download_url='https://github.com/philippelt/netatmo-api-python/tarball/v1.5.1.tar.gz',
20+
download_url='https://github.com/philippelt/netatmo-api-python/tarball/v1.6.0.tar.gz',
2121
license='GPL V3',
2222
description='Simple API to access Netatmo weather station data from any python script.'
2323
)

0 commit comments

Comments
 (0)