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 2016-10-08 20:26:01 +02:00 committed by Paulus Schoutsen
parent 1e2e877302
commit bbbb4441ea
3 changed files with 23 additions and 9 deletions

View file

@ -16,7 +16,7 @@ import homeassistant.helpers.config_validation as cv
REQUIREMENTS = [
'https://github.com/jabesq/netatmo-api-python/archive/'
'v0.5.0.zip#lnetatmo==0.5.0']
'v0.6.0.zip#lnetatmo==0.6.0']
_LOGGER = logging.getLogger(__name__)

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)

View file

@ -174,7 +174,7 @@ https://github.com/danieljkemp/onkyo-eiscp/archive/python3.zip#onkyo-eiscp==0.9.
https://github.com/gadgetreactor/pyHS100/archive/ef85f939fd5b07064a0f34dfa673fa7d6140bd95.zip#pyHS100==0.1.2
# homeassistant.components.netatmo
https://github.com/jabesq/netatmo-api-python/archive/v0.5.0.zip#lnetatmo==0.5.0
https://github.com/jabesq/netatmo-api-python/archive/v0.6.0.zip#lnetatmo==0.6.0
# homeassistant.components.sensor.sabnzbd
https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1