Add station name for creating the unique_id in netatmo platform (#24141)

This commit is contained in:
maheus 2019-05-27 18:07:59 +02:00 committed by Pascal Vizeli
parent 9678752480
commit c840771c0a

View File

@ -145,7 +145,8 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
# Only create sensors for monitored properties # Only create sensors for monitored properties
for condition in monitored_conditions: for condition in monitored_conditions:
dev.append(NetatmoSensor( dev.append(NetatmoSensor(
data, module_name, condition.lower())) data, module_name, condition.lower(),
config.get(CONF_STATION)))
for module_name, _ in not_handled.items(): for module_name, _ in not_handled.items():
_LOGGER.error('Module name: "%s" not found', module_name) _LOGGER.error('Module name: "%s" not found', module_name)
@ -164,13 +165,14 @@ def all_product_classes():
class NetatmoSensor(Entity): class NetatmoSensor(Entity):
"""Implementation of a Netatmo sensor.""" """Implementation of a Netatmo sensor."""
def __init__(self, netatmo_data, module_name, sensor_type): def __init__(self, netatmo_data, module_name, sensor_type, station):
"""Initialize the sensor.""" """Initialize the sensor."""
self._name = 'Netatmo {} {}'.format(module_name, self._name = 'Netatmo {} {}'.format(module_name,
SENSOR_TYPES[sensor_type][0]) SENSOR_TYPES[sensor_type][0])
self.netatmo_data = netatmo_data self.netatmo_data = netatmo_data
self.module_name = module_name self.module_name = module_name
self.type = sensor_type self.type = sensor_type
self.station_name = station
self._state = None self._state = None
self._device_class = SENSOR_TYPES[self.type][3] self._device_class = SENSOR_TYPES[self.type][3]
self._icon = SENSOR_TYPES[self.type][2] self._icon = SENSOR_TYPES[self.type][2]
@ -178,7 +180,8 @@ class NetatmoSensor(Entity):
self._module_type = self.netatmo_data. \ self._module_type = self.netatmo_data. \
station_data.moduleByName(module=module_name)['type'] station_data.moduleByName(module=module_name)['type']
module_id = self.netatmo_data. \ module_id = self.netatmo_data. \
station_data.moduleByName(module=module_name)['_id'] station_data.moduleByName(station=self.station_name,
module=module_name)['_id']
self._unique_id = '{}-{}'.format(module_id, self.type) self._unique_id = '{}-{}'.format(module_id, self.type)
@property @property