@@ -292,6 +292,7 @@ def __init__(self, authData, home=None, station=None):
292
292
if not self .rawData : raise NoDevice ("No weather station in any homes" )
293
293
# Stations are no longer in the Netatmo API, keeping them for compatibility
294
294
self .stations = { d ['station_name' ] : d for d in self .rawData }
295
+ self .stationIds = { d ['_id' ] : d for d in self .rawData }
295
296
self .homes = { d ['home_name' ] : d ["station_name" ] for d in self .rawData }
296
297
# Keeping the old behavior for default station name
297
298
if home and home not in self .homes : raise NoHome ("No home with name %s" % home )
@@ -331,15 +332,13 @@ def modulesNamesList(self, station=None, home=None):
331
332
332
333
def stationByName (self , station = None ):
333
334
if not station : station = self .default_station
334
- for i ,s in self .stations .items ():
335
- if s ['station_name' ] == station :
336
- return self .stations [i ]
337
- return None
335
+ if station not in self .stations : return None
336
+ return self .stations [station ]
338
337
339
338
def stationById (self , sid ):
340
- for s in self .stations :
341
- if sid == self .stations [ s ][ "_id" ] : return self . stations [ s ]
342
- return None
339
+ if not sid : return self .stations [ self . default_station ]
340
+ if sid not in self .stationIds : return None
341
+ return self . stationIds [ sid ]
343
342
344
343
def moduleByName (self , module ):
345
344
for m in self .modules :
0 commit comments