Enhancements to ARWN platform (#5816)

* Fix arwn platform discover_sensors

The discover_sensors function can return either singletons or a list
of sensors. However the consumer was always expecting a list. This
fixes it to work in both cases.

* Add custom icons to arwn sensors.

This adds some custom icons for different kinds of weather sensors
that the arwn platform returns. Makes it a little easier to see what's
going on.
This commit is contained in:
Sean Dague 2017-02-08 22:56:44 -05:00 committed by Paulus Schoutsen
parent 76db4cc099
commit 49f2540730

View File

@ -35,11 +35,12 @@ def discover_sensors(topic, payload):
unit = TEMP_CELSIUS unit = TEMP_CELSIUS
return ArwnSensor(name, 'temp', unit) return ArwnSensor(name, 'temp', unit)
if domain == 'barometer': if domain == 'barometer':
return ArwnSensor('Barometer', 'pressure', unit) return ArwnSensor('Barometer', 'pressure', unit,
"mdi:thermometer-lines")
if domain == 'wind': if domain == 'wind':
return (ArwnSensor('Wind Speed', 'speed', unit), return (ArwnSensor('Wind Speed', 'speed', unit, "mdi:speedometer"),
ArwnSensor('Wind Gust', 'gust', unit), ArwnSensor('Wind Gust', 'gust', unit, "mdi:speedometer"),
ArwnSensor('Wind Direction', 'direction', '°')) ArwnSensor('Wind Direction', 'direction', '°', "mdi:compass"))
def _slug(name): def _slug(name):
@ -66,6 +67,9 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
if not sensors: if not sensors:
return return
if isinstance(sensors, ArwnSensor):
sensors = (sensors, )
if 'timestamp' in event: if 'timestamp' in event:
del event['timestamp'] del event['timestamp']
@ -88,7 +92,7 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
class ArwnSensor(Entity): class ArwnSensor(Entity):
"""Representation of an ARWN sensor.""" """Representation of an ARWN sensor."""
def __init__(self, name, state_key, units): def __init__(self, name, state_key, units, icon=None):
"""Initialize the sensor.""" """Initialize the sensor."""
self.hass = None self.hass = None
self.entity_id = _slug(name) self.entity_id = _slug(name)
@ -96,6 +100,7 @@ class ArwnSensor(Entity):
self._state_key = state_key self._state_key = state_key
self.event = {} self.event = {}
self._unit_of_measurement = units self._unit_of_measurement = units
self._icon = icon
def set_event(self, event): def set_event(self, event):
"""Update the sensor with the most recent event.""" """Update the sensor with the most recent event."""
@ -126,3 +131,11 @@ class ArwnSensor(Entity):
def should_poll(self): def should_poll(self):
"""Should we poll.""" """Should we poll."""
return False return False
@property
def icon(self):
"""Icon of device based on its type."""
if self._icon:
return self._icon
else:
return super().icon