Make icon configurable

This commit is contained in:
Michael Wyraz
2017-04-06 19:25:18 +02:00
parent 11cde32b20
commit fe45aec82d

View File

@@ -33,8 +33,9 @@ ATTR_TO_PROPERTY = [
CONF_ENTITY_IDS = 'entity_ids' CONF_ENTITY_IDS = 'entity_ids'
CONF_ROUND_DIGITS = 'round_digits' CONF_ROUND_DIGITS = 'round_digits'
CONF_ICON = 'icon'
ICON = 'mdi:calculator' DEFAULT_ICON = 'mdi:calculator'
SENSOR_TYPES = { SENSOR_TYPES = {
ATTR_MIN_VALUE: 'min', ATTR_MIN_VALUE: 'min',
@@ -48,6 +49,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Optional(CONF_NAME): cv.string, vol.Optional(CONF_NAME): cv.string,
vol.Required(CONF_ENTITY_IDS): cv.entity_ids, vol.Required(CONF_ENTITY_IDS): cv.entity_ids,
vol.Optional(CONF_ROUND_DIGITS, default=2): vol.Coerce(int), vol.Optional(CONF_ROUND_DIGITS, default=2): vol.Coerce(int),
vol.Optional(CONF_ICON, default=DEFAULT_ICON): cv.string,
}) })
@@ -58,9 +60,10 @@ def async_setup_platform(hass, config, async_add_devices, discovery_info=None):
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
sensor_type = config.get(CONF_TYPE) sensor_type = config.get(CONF_TYPE)
round_digits = config.get(CONF_ROUND_DIGITS) round_digits = config.get(CONF_ROUND_DIGITS)
icon = config.get(CONF_ICON)
async_add_devices( async_add_devices(
[MinMaxSensor(hass, entity_ids, name, sensor_type, round_digits)], [MinMaxSensor(hass, entity_ids, name, sensor_type, round_digits, icon)],
True) True)
return True return True
@@ -101,12 +104,13 @@ def calc_mean(sensor_values, round_digits):
class MinMaxSensor(Entity): class MinMaxSensor(Entity):
"""Representation of a min/max sensor.""" """Representation of a min/max sensor."""
def __init__(self, hass, entity_ids, name, sensor_type, round_digits): def __init__(self, hass, entity_ids, name, sensor_type, round_digits, icon):
"""Initialize the min/max sensor.""" """Initialize the min/max sensor."""
self._hass = hass self._hass = hass
self._entity_ids = entity_ids self._entity_ids = entity_ids
self._sensor_type = sensor_type self._sensor_type = sensor_type
self._round_digits = round_digits self._round_digits = round_digits
seld._icon = icon
if name: if name:
self._name = name self._name = name
@@ -188,7 +192,7 @@ class MinMaxSensor(Entity):
@property @property
def icon(self): def icon(self):
"""Return the icon to use in the frontend, if any.""" """Return the icon to use in the frontend, if any."""
return ICON return self._icon
@asyncio.coroutine @asyncio.coroutine
def async_update(self): def async_update(self):