Skip to content

Commit

Permalink
Add discovery support for Netatmo weather Station (home-assistant#3714)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
jabesq authored and balloob committed Oct 8, 2016
1 parent 1e2e877 commit bbbb444
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

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__)

Expand Down
28 changes: 21 additions & 7 deletions homeassistant/components/sensor/netatmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_STATION): cv.string,
vol.Required(CONF_MODULES): MODULE_SCHEMA,
vol.Optional(CONF_MODULES): MODULE_SCHEMA,
})


Expand All @@ -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 """
Expand All @@ -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)

Expand All @@ -94,13 +96,23 @@ def __init__(self, netatmo_data, module_name, sensor_type):
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
def name(self):
"""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."""
Expand Down Expand Up @@ -222,6 +234,7 @@ def __init__(self, auth, station):
"""Initialize the data object."""
self.auth = auth
self.data = None
self.station_data = None
self.station = station

def get_module_names(self):
Expand All @@ -233,9 +246,10 @@ def get_module_names(self):
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)
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bbbb444

Please sign in to comment.