Skip to content

Commit dee863d

Browse files
committed
Fix #23 and #24
1 parent 26ce4d7 commit dee863d

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lnetatmo.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ def __init__(self, authData):
262262
self.stations = { d['_id'] : d for d in self.rawData }
263263
self.modules = dict()
264264
for i in range(len(self.rawData)):
265-
for m in self.rawData[i]['modules']:
266-
self.modules[ m['_id'] ] = m
265+
# Loop on external modules if they are present
266+
if 'modules' in self.rawData[i]:
267+
for m in self.rawData[i]['modules']:
268+
self.modules[ m['_id'] ] = m
267269
self.default_station = list(self.stations.values())[0]['station_name']
268270

269271
def modulesNamesList(self, station=None):
@@ -309,20 +311,21 @@ def lastData(self, station=None, exclude=0):
309311
# Define oldest acceptable sensor measure event
310312
limit = (time.time() - exclude) if exclude else 0
311313
ds = s['dashboard_data']
312-
if ds['time_utc'] > limit :
314+
if ds.get('time_utc',limit+10) > limit :
313315
lastD[s['module_name']] = ds.copy()
314-
lastD[s['module_name']]['When'] = lastD[s['module_name']].pop("time_utc")
316+
lastD[s['module_name']]['When'] = lastD[s['module_name']].pop("time_utc") if 'time_utc' in lastD[s['module_name']] else time.time()
315317
lastD[s['module_name']]['wifi_status'] = s['wifi_status']
316-
for module in s["modules"]:
317-
ds = module['dashboard_data']
318-
if ds['time_utc'] > limit :
319-
# If no module_name has been setup, use _id by default
320-
if "module_name" not in module : module['module_name'] = module["_id"]
321-
lastD[module['module_name']] = ds.copy()
322-
lastD[module['module_name']]['When'] = lastD[module['module_name']].pop("time_utc")
323-
# For potential use, add battery and radio coverage information to module data if present
324-
for i in ('battery_vp', 'rf_status') :
325-
if i in module : lastD[module['module_name']][i] = module[i]
318+
if 'modules' in s:
319+
for module in s["modules"]:
320+
ds = module['dashboard_data']
321+
if ds.get('time_utc',limit+10) > limit :
322+
# If no module_name has been setup, use _id by default
323+
if "module_name" not in module : module['module_name'] = module["_id"]
324+
lastD[module['module_name']] = ds.copy()
325+
lastD[s['module_name']]['When'] = lastD[s['module_name']].pop("time_utc") if 'time_utc' in lastD[s['module_name']] else time.time()
326+
# For potential use, add battery and radio coverage information to module data if present
327+
for i in ('battery_vp', 'rf_status') :
328+
if i in module : lastD[module['module_name']][i] = module[i]
326329
return lastD
327330

328331
def checkNotUpdated(self, station=None, delay=3600):

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.4.3',
7+
version='1.4.4',
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.4.3.tar.gz',
20+
download_url='https://github.com/philippelt/netatmo-api-python/tarball/v1.4.4.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)