Add sms_total sensor to netgear_lte (#22954)

This commit is contained in:
Anders Melchiorsen 2019-04-10 09:41:57 +02:00 committed by GitHub
parent 6d2412022b
commit a833736a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 3 deletions

View File

@ -5,7 +5,8 @@ from homeassistant.components.sensor import DOMAIN
from homeassistant.exceptions import PlatformNotReady
from . import CONF_MONITORED_CONDITIONS, DATA_KEY, LTEEntity
from .sensor_types import SENSOR_SMS, SENSOR_USAGE, SENSOR_UNITS
from .sensor_types import (
SENSOR_SMS, SENSOR_SMS_TOTAL, SENSOR_USAGE, SENSOR_UNITS)
DEPENDENCIES = ['netgear_lte']
@ -29,7 +30,9 @@ async def async_setup_platform(
sensors = []
for sensor_type in monitored_conditions:
if sensor_type == SENSOR_SMS:
sensors.append(SMSSensor(modem_data, sensor_type))
sensors.append(SMSUnreadSensor(modem_data, sensor_type))
elif sensor_type == SENSOR_SMS_TOTAL:
sensors.append(SMSTotalSensor(modem_data, sensor_type))
elif sensor_type == SENSOR_USAGE:
sensors.append(UsageSensor(modem_data, sensor_type))
else:
@ -47,7 +50,7 @@ class LTESensor(LTEEntity):
return SENSOR_UNITS[self.sensor_type]
class SMSSensor(LTESensor):
class SMSUnreadSensor(LTESensor):
"""Unread SMS sensor entity."""
@property
@ -56,6 +59,15 @@ class SMSSensor(LTESensor):
return sum(1 for x in self.modem_data.data.sms if x.unread)
class SMSTotalSensor(LTESensor):
"""Total SMS sensor entity."""
@property
def state(self):
"""Return the state of the sensor."""
return len(self.modem_data.data.sms)
class UsageSensor(LTESensor):
"""Data usage sensor entity."""

View File

@ -3,10 +3,12 @@
from homeassistant.components.binary_sensor import DEVICE_CLASS_CONNECTIVITY
SENSOR_SMS = 'sms'
SENSOR_SMS_TOTAL = 'sms_total'
SENSOR_USAGE = 'usage'
SENSOR_UNITS = {
SENSOR_SMS: 'unread',
SENSOR_SMS_TOTAL: 'messages',
SENSOR_USAGE: 'MiB',
'radio_quality': '%',
'rx_level': 'dBm',