Make asuswrt sensor optional (#19736) @kennedyshead

* Dont load if not in config

* Adding config options for sensors

* Fixed mistake with iterating over wrong things

* lint

* lint

* Setting None state

* Using .get when fetching optional config
This commit is contained in:
kennedyshead authored and Eric Nagley committed 2019-01-08 09:14:16 -05:00
1 parent 410f19c777
commit 377b129c9c
2 files changed
+23 -8

No files matched your search

+16 -6
View File
@@ -17,13 +17,23 @@ _LOGGER = logging.getLogger(__name__)
async def async_setup_platform(
hass, config, add_entities, discovery_info=None):
"""Set up the asuswrt sensors."""
if discovery_info is None:
return
api = hass.data[DATA_ASUSWRT]
add_entities([
AsuswrtRXSensor(api),
AsuswrtTXSensor(api),
AsuswrtTotalRXSensor(api),
AsuswrtTotalTXSensor(api)
])
devices = []
if 'download' in discovery_info:
devices.append(AsuswrtTotalRXSensor(api))
if 'upload' in discovery_info:
devices.append(AsuswrtTotalTXSensor(api))
if 'download_speed' in discovery_info:
devices.append(AsuswrtRXSensor(api))
if 'upload_speed' in discovery_info:
devices.append(AsuswrtTXSensor(api))
add_entities(devices)
class AsuswrtSensor(Entity):