mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add unique_id to netgear_lte sensors (#15584)
This commit is contained in:
parent
ee8a815e6b
commit
d1b16e287c
@ -17,7 +17,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
REQUIREMENTS = ['eternalegypt==0.0.2']
|
REQUIREMENTS = ['eternalegypt==0.0.3']
|
||||||
|
|
||||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10)
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10)
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ class ModemData:
|
|||||||
"""Class for modem state."""
|
"""Class for modem state."""
|
||||||
|
|
||||||
modem = attr.ib()
|
modem = attr.ib()
|
||||||
|
serial_number = attr.ib(init=False)
|
||||||
unread_count = attr.ib(init=False)
|
unread_count = attr.ib(init=False)
|
||||||
usage = attr.ib(init=False)
|
usage = attr.ib(init=False)
|
||||||
|
|
||||||
@ -44,6 +45,7 @@ class ModemData:
|
|||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Call the API to update the data."""
|
"""Call the API to update the data."""
|
||||||
information = await self.modem.information()
|
information = await self.modem.information()
|
||||||
|
self.serial_number = information.serial_number
|
||||||
self.unread_count = sum(1 for x in information.sms if x.unread)
|
self.unread_count = sum(1 for x in information.sms if x.unread)
|
||||||
self.usage = information.usage
|
self.usage = information.usage
|
||||||
|
|
||||||
|
@ -32,11 +32,11 @@ async def async_setup_platform(
|
|||||||
modem_data = hass.data[DATA_KEY].get_modem_data(config)
|
modem_data = hass.data[DATA_KEY].get_modem_data(config)
|
||||||
|
|
||||||
sensors = []
|
sensors = []
|
||||||
for sensortype in config[CONF_SENSORS]:
|
for sensor_type in config[CONF_SENSORS]:
|
||||||
if sensortype == SENSOR_SMS:
|
if sensor_type == SENSOR_SMS:
|
||||||
sensors.append(SMSSensor(modem_data))
|
sensors.append(SMSSensor(modem_data, sensor_type))
|
||||||
elif sensortype == SENSOR_USAGE:
|
elif sensor_type == SENSOR_USAGE:
|
||||||
sensors.append(UsageSensor(modem_data))
|
sensors.append(UsageSensor(modem_data, sensor_type))
|
||||||
|
|
||||||
async_add_devices(sensors, True)
|
async_add_devices(sensors, True)
|
||||||
|
|
||||||
@ -46,11 +46,17 @@ class LTESensor(Entity):
|
|||||||
"""Data usage sensor entity."""
|
"""Data usage sensor entity."""
|
||||||
|
|
||||||
modem_data = attr.ib()
|
modem_data = attr.ib()
|
||||||
|
sensor_type = attr.ib()
|
||||||
|
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Update state."""
|
"""Update state."""
|
||||||
await self.modem_data.async_update()
|
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):
|
class SMSSensor(LTESensor):
|
||||||
"""Unread SMS sensor entity."""
|
"""Unread SMS sensor entity."""
|
||||||
|
@ -309,7 +309,7 @@ ephem==3.7.6.0
|
|||||||
epson-projector==0.1.3
|
epson-projector==0.1.3
|
||||||
|
|
||||||
# homeassistant.components.netgear_lte
|
# homeassistant.components.netgear_lte
|
||||||
eternalegypt==0.0.2
|
eternalegypt==0.0.3
|
||||||
|
|
||||||
# homeassistant.components.keyboard_remote
|
# homeassistant.components.keyboard_remote
|
||||||
# evdev==0.6.1
|
# evdev==0.6.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user