Add unique_id to netgear_lte sensors (#15584)

This commit is contained in:
Anders Melchiorsen authored and Martin Hjelmare committed 2018-07-21 10:14:56 +02:00
1 parent ee8a815e6b
commit d1b16e287c
3 files changed
+15 -7

No files matched your search

+11 -5
View File
@@ -32,11 +32,11 @@ async def async_setup_platform(
modem_data = hass.data[DATA_KEY].get_modem_data(config)
sensors = []
for sensortype in config[CONF_SENSORS]:
if sensortype == SENSOR_SMS:
sensors.append(SMSSensor(modem_data))
elif sensortype == SENSOR_USAGE:
sensors.append(UsageSensor(modem_data))
for sensor_type in config[CONF_SENSORS]:
if sensor_type == SENSOR_SMS:
sensors.append(SMSSensor(modem_data, sensor_type))
elif sensor_type == SENSOR_USAGE:
sensors.append(UsageSensor(modem_data, sensor_type))
async_add_devices(sensors, True)
@@ -46,11 +46,17 @@ class LTESensor(Entity):
"""Data usage sensor entity."""
modem_data = attr.ib()
sensor_type = attr.ib()
async def async_update(self):
"""Update state."""
await self.modem_data.async_update()
@property
def unique_id(self):
"""Return a unique ID like 'usage_5TG365AB0078V'."""
return "{}_{}".format(self.sensor_type, self.modem_data.serial_number)
class SMSSensor(LTESensor):
"""Unread SMS sensor entity."""