Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/netgear_lte.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from homeassistant.helpers.aiohttp_client import async_create_clientsession
from homeassistant.util import Throttle

REQUIREMENTS = ['eternalegypt==0.0.2']
REQUIREMENTS = ['eternalegypt==0.0.3']

MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=10)

Expand All @@ -37,13 +37,15 @@ class ModemData:
"""Class for modem state."""

modem = attr.ib()
serial_number = attr.ib(init=False)
unread_count = attr.ib(init=False)
usage = attr.ib(init=False)

@Throttle(MIN_TIME_BETWEEN_UPDATES)
async def async_update(self):
"""Call the API to update the data."""
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.usage = information.usage

Expand Down
16 changes: 11 additions & 5 deletions homeassistant/components/sensor/netgear_lte.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ ephem==3.7.6.0
epson-projector==0.1.3

# homeassistant.components.netgear_lte
eternalegypt==0.0.2
eternalegypt==0.0.3

# homeassistant.components.keyboard_remote
# evdev==0.6.1
Expand Down