Make icon configurable
This commit is contained in:
parent
11cde32b20
commit
fe45aec82d
1 changed files with 8 additions and 4 deletions
|
@ -33,8 +33,9 @@ ATTR_TO_PROPERTY = [
|
|||
|
||||
CONF_ENTITY_IDS = 'entity_ids'
|
||||
CONF_ROUND_DIGITS = 'round_digits'
|
||||
CONF_ICON = 'icon'
|
||||
|
||||
ICON = 'mdi:calculator'
|
||||
DEFAULT_ICON = 'mdi:calculator'
|
||||
|
||||
SENSOR_TYPES = {
|
||||
ATTR_MIN_VALUE: 'min',
|
||||
|
@ -48,6 +49,7 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
|||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_ENTITY_IDS): cv.entity_ids,
|
||||
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)
|
||||
sensor_type = config.get(CONF_TYPE)
|
||||
round_digits = config.get(CONF_ROUND_DIGITS)
|
||||
icon = config.get(CONF_ICON)
|
||||
|
||||
async_add_devices(
|
||||
[MinMaxSensor(hass, entity_ids, name, sensor_type, round_digits)],
|
||||
[MinMaxSensor(hass, entity_ids, name, sensor_type, round_digits, icon)],
|
||||
True)
|
||||
return True
|
||||
|
||||
|
@ -101,12 +104,13 @@ def calc_mean(sensor_values, round_digits):
|
|||
class MinMaxSensor(Entity):
|
||||
"""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."""
|
||||
self._hass = hass
|
||||
self._entity_ids = entity_ids
|
||||
self._sensor_type = sensor_type
|
||||
self._round_digits = round_digits
|
||||
seld._icon = icon
|
||||
|
||||
if name:
|
||||
self._name = name
|
||||
|
@ -188,7 +192,7 @@ class MinMaxSensor(Entity):
|
|||
@property
|
||||
def icon(self):
|
||||
"""Return the icon to use in the frontend, if any."""
|
||||
return ICON
|
||||
return self._icon
|
||||
|
||||
@asyncio.coroutine
|
||||
def async_update(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue