New option for the netatmo platform: station (#2178)

This is necessary if multiple weather stations are associated with
one Netatmo account.
This commit is contained in:
rubund 2016-05-29 23:25:11 +02:00 committed by Paulus Schoutsen
parent e886303f08
commit 03e8627b12

View File

@ -33,6 +33,7 @@ SENSOR_TYPES = {
}
CONF_SECRET_KEY = 'secret_key'
CONF_STATION = 'station'
ATTR_MODULE = 'modules'
# Return cached results if last scan was less then this time ago
@ -64,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
"Please check your settings for NatAtmo API.")
return False
data = NetAtmoData(authorization)
data = NetAtmoData(authorization, config.get(CONF_STATION, None))
dev = []
try:
@ -149,10 +150,11 @@ class NetAtmoSensor(Entity):
class NetAtmoData(object):
"""Get the latest data from NetAtmo."""
def __init__(self, auth):
def __init__(self, auth, station):
"""Initialize the data object."""
self.auth = auth
self.data = None
self.station = station
def get_module_names(self):
"""Return all module available on the API as a list."""
@ -164,4 +166,8 @@ class NetAtmoData(object):
"""Call the NetAtmo API to update the data."""
import lnetatmo
dev_list = lnetatmo.DeviceList(self.auth)
self.data = dev_list.lastData(exclude=3600)
if self.station is not None:
self.data = dev_list.lastData(station=self.station, exclude=3600)
else:
self.data = dev_list.lastData(exclude=3600)