Add discovery support for Netatmo weather Station (#3714)

* Add discovery support for Netatmo Weather station

Only The weather information are currently supported (No battery or wifi status supported)

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Add unique_id for netatmo sensors to avoid duplicate

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>

* Update requirements_all.txt and PEP8 fixes

Signed-off-by: Hugo D. (jabesq) <jabesq@gmail.com>
This commit is contained in:
Hugo Dupras authored and Paulus Schoutsen committed 2016-10-08 11:26:01 -07:00
1 parent 1e2e877302
commit bbbb4441ea
3 files changed
+23 -9

No files matched your search

+21 -7
View File
@@ -55,7 +55,7 @@ MODULE_SCHEMA = vol.Schema({
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_STATION): cv.string,
vol.Required(CONF_MODULES): MODULE_SCHEMA,
vol.Optional(CONF_MODULES): MODULE_SCHEMA,
})
@@ -65,7 +65,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
data = NetAtmoData(netatmo.NETATMO_AUTH, config.get(CONF_STATION, None))
dev = []
try:
if CONF_MODULES in config:
# Iterate each module
for module_name, monitored_conditions in config[CONF_MODULES].items():
# Test if module exist """
@@ -75,8 +75,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
# Only create sensor for monitored """
for variable in monitored_conditions:
dev.append(NetAtmoSensor(data, module_name, variable))
except KeyError:
pass
else:
for module_name in data.get_module_names():
for variable in data.station_data.monitoredConditions(module_name):
dev.append(NetAtmoSensor(data, module_name, variable))
add_devices(dev)
@@ -94,6 +96,11 @@ class NetAtmoSensor(Entity):
self.type = sensor_type
self._state = None
self._unit_of_measurement = SENSOR_TYPES[sensor_type][1]
module_id = self.netatmo_data.\
station_data.moduleByName(module=module_name)['_id']
self._unique_id = "Netatmo Sensor {0} - {1} ({2})".format(self._name,
module_id,
self.type)
self.update()
@property
@@ -101,6 +108,11 @@ class NetAtmoSensor(Entity):
"""Return the name of the sensor."""
return self._name
@property
def unique_id(self):
"""Return the unique ID for this sensor."""
return self._unique_id
@property
def icon(self):
"""Icon to use in the frontend, if any."""
@@ -222,6 +234,7 @@ class NetAtmoData(object):
"""Initialize the data object."""
self.auth = auth
self.data = None
self.station_data = None
self.station = station
def get_module_names(self):
@@ -233,9 +246,10 @@ class NetAtmoData(object):
def update(self):
"""Call the Netatmo API to update the data."""
import lnetatmo
dev_list = lnetatmo.DeviceList(self.auth)
self.station_data = lnetatmo.DeviceList(self.auth)
if self.station is not None:
self.data = dev_list.lastData(station=self.station, exclude=3600)
self.data = self.station_data.lastData(station=self.station,
exclude=3600)
else:
self.data = dev_list.lastData(exclude=3600)
self.data = self.station_data.lastData(exclude=3600)