@@ -292,6 +292,7 @@ def __init__(self, authData, home=None, station=None):
292292 if not self .rawData : raise NoDevice ("No weather station in any homes" )
293293 # Stations are no longer in the Netatmo API, keeping them for compatibility
294294 self .stations = { d ['station_name' ] : d for d in self .rawData }
295+ self .stationIds = { d ['_id' ] : d for d in self .rawData }
295296 self .homes = { d ['home_name' ] : d ["station_name" ] for d in self .rawData }
296297 # Keeping the old behavior for default station name
297298 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):
331332
332333 def stationByName (self , station = None ):
333334 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 ]
338337
339338 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 ]
343342
344343 def moduleByName (self , module ):
345344 for m in self .modules :
0 commit comments