Skip to content

Commit 73e5ea4

Browse files
committed
[Change] Allow station access by id to handle duplicate name #53
1 parent 8e2d606 commit 73e5ea4

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lnetatmo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

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='3.0.3',
7+
version='3.1.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/archive/v3.0.3.tar.gz',
20+
download_url='https://github.com/philippelt/netatmo-api-python/archive/v3.1.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)