Skip to content

Commit 0288e68

Browse files
committed
[Change] Allow name or id in station parameters of WeatherStationData or lastData
1 parent bcd4b3e commit 0288e68

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

lnetatmo.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,17 @@ def __init__(self, authData, home=None, station=None):
293293
# Keeping the old behavior for default station name
294294
if home and home not in self.homes : raise NoHome("No home with name %s" % home)
295295
self.default_home = home or list(self.homes.keys())[0]
296-
if station and station not in self.stations: raise NoDevice("No station with name %s" % station)
297-
self.default_station = station or [v["station_name"] for k,v in self.stations.items() if v["home_name"] == self.default_home][0]
296+
if station:
297+
if station not in self.stations:
298+
# May be a station_id convert it to corresponding station name
299+
s = self.stationById(station)
300+
if s :
301+
station = s["station_name"]
302+
else:
303+
raise NoDevice("No station with name or id %s" % station)
304+
self.default_station = station
305+
else:
306+
self.default_station = [v["station_name"] for k,v in self.stations.items() if v["home_name"] == self.default_home][0]
298307
self.modules = dict()
299308
self.default_station_data = self.stationByName(self.default_station)
300309
if 'modules' in self.default_station_data:
@@ -313,6 +322,7 @@ def __init__(self, authData, home=None, station=None):
313322

314323
def modulesNamesList(self, station=None, home=None):
315324
res = [m['module_name'] for m in self.modules.values()]
325+
station = self.stationByName(station) or self.stationById(station)
316326
res.append(self.stationByName(station)['module_name'])
317327
return res
318328

@@ -324,7 +334,9 @@ def stationByName(self, station=None):
324334
return None
325335

326336
def stationById(self, sid):
327-
return self.stations.get(sid)
337+
for s in self.stations:
338+
if sid == self.stations[s]["_id"]: return self.stations[s]
339+
return None
328340

329341
def moduleByName(self, module):
330342
for m in self.modules:
@@ -337,7 +349,7 @@ def moduleById(self, mid):
337349
return self.modules.get(mid)
338350

339351
def lastData(self, station=None, exclude=0):
340-
s = self.stationByName(station)
352+
s = self.stationByName(station) or self.stationById(station)
341353
# Breaking change from Netatmo : dashboard_data no longer available if station lost
342354
if not s or 'dashboard_data' not in s : return None
343355
lastD = dict()

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.1',
7+
version='3.0.2',
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.1.tar.gz',
20+
download_url='https://github.com/philippelt/netatmo-api-python/archive/v3.0.2.tar.gz',
2121
license='GPL V3',
2222
description='Simple API to access Netatmo weather station data from any python script.'
2323
)

usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Constructor
226226
```
227227

228228

229-
* Input : an authorization object (ClientAuth instance), an optional home name, an optional station name
229+
* Input : an authorization object (ClientAuth instance), an optional home name, an optional station name or id
230230

231231
Return : a WeatherStationData object. This object contains most administration properties of stations and modules accessible to the user and the last data pushed by the station to the Netatmo servers.
232232

0 commit comments

Comments
 (0)