Binary sensors for netgear_lte (#22902)
* Binary sensors for netgear_lte * Move LTEEntity to component * Revert unrelated manifest changes * Address review comments * Remove unused import
This commit is contained in:
1 parent
4803f319b6
commit
58ec77b017
6 files changed
+136
-58
No files matched your search
@@ -1,14 +1,10 @@
|
||||
"""Support for Netgear LTE sensors."""
|
||||
import logging
|
||||
|
||||
import attr
|
||||
|
||||
from homeassistant.components.sensor import DOMAIN
|
||||
from homeassistant.exceptions import PlatformNotReady
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
from . import CONF_MONITORED_CONDITIONS, DATA_KEY, DISPATCHER_NETGEAR_LTE
|
||||
from . import CONF_MONITORED_CONDITIONS, DATA_KEY, LTEEntity
|
||||
from .sensor_types import SENSOR_SMS, SENSOR_USAGE, SENSOR_UNITS
|
||||
|
||||
DEPENDENCIES = ['netgear_lte']
|
||||
@@ -42,50 +38,9 @@ async def async_setup_platform(
|
||||
async_add_entities(sensors)
|
||||
|
||||
|
||||
@attr.s
|
||||
class LTESensor(Entity):
|
||||
class LTESensor(LTEEntity):
|
||||
"""Base LTE sensor entity."""
|
||||
|
||||
modem_data = attr.ib()
|
||||
sensor_type = attr.ib()
|
||||
|
||||
_unique_id = attr.ib(init=False)
|
||||
|
||||
@_unique_id.default
|
||||
def _init_unique_id(self):
|
||||
"""Register unique_id while we know data is valid."""
|
||||
return "{}_{}".format(
|
||||
self.sensor_type, self.modem_data.data.serial_number)
|
||||
|
||||
async def async_added_to_hass(self):
|
||||
"""Register callback."""
|
||||
async_dispatcher_connect(
|
||||
self.hass, DISPATCHER_NETGEAR_LTE, self.async_write_ha_state)
|
||||
|
||||
async def async_update(self):
|
||||
"""Force update of state."""
|
||||
await self.modem_data.async_update()
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""Return that the sensor should not be polled."""
|
||||
return False
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return the availability of the sensor."""
|
||||
return self.modem_data.data is not None
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Return a unique ID like 'usage_5TG365AB0078V'."""
|
||||
return self._unique_id
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return "Netgear LTE {}".format(self.sensor_type)
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement."""
|
||||
|
||||
Reference in new issue
Block a user