Skip to content

Commit 5a706ba

Browse files
committed
Fix #29 and #30
1 parent fcfc009 commit 5a706ba

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lnetatmo.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ def moduleById(self, mid, sid=None):
306306

307307
def lastData(self, station=None, exclude=0):
308308
s = self.stationByName(station) or self.stationById(station)
309-
if not s : return None
309+
# Breaking change from Netatmo : dashboard_data no longer available if station lost
310+
if not s or 'dashboard_data' not in s : return None
310311
lastD = dict()
311312
# Define oldest acceptable sensor measure event
312313
limit = (time.time() - exclude) if exclude else 0
@@ -429,15 +430,18 @@ def __init__(self, authData):
429430
nameHome = curHome['name']
430431
if nameHome not in self.cameras:
431432
self.cameras[nameHome] = dict()
432-
for p in curHome['persons']:
433-
self.persons[ p['id'] ] = p
434-
for e in curHome['events']:
435-
if e['camera_id'] not in self.events:
436-
self.events[ e['camera_id'] ] = dict()
437-
self.events[ e['camera_id'] ][ e['time'] ] = e
438-
for c in curHome['cameras']:
439-
self.cameras[nameHome][ c['id'] ] = c
440-
c["home_id"] = curHome['id']
433+
if 'persons' in curHome:
434+
for p in curHome['persons']:
435+
self.persons[ p['id'] ] = p
436+
if 'events' in curHome:
437+
for e in curHome['events']:
438+
if e['camera_id'] not in self.events:
439+
self.events[ e['camera_id'] ] = dict()
440+
self.events[ e['camera_id'] ][ e['time'] ] = e
441+
if 'cameras' in curHome:
442+
for c in curHome['cameras']:
443+
self.cameras[nameHome][ c['id'] ] = c
444+
c["home_id"] = curHome['id']
441445
for camera in self.events:
442446
self.lastEvent[camera] = self.events[camera][sorted(self.events[camera])[-1]]
443447
if not self.cameras[self.default_home] : raise NoDevice("No camera available in default home")

0 commit comments

Comments
 (0)