From fe45aec82d9a07e730bebb4d47dc9618fb695fe6 Mon Sep 17 00:00:00 2001 From: Michael Wyraz Date: Thu, 6 Apr 2017 19:25:18 +0200 Subject: [PATCH] Make icon configurable --- homeassistant/components/sensor/min_max.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/sensor/min_max.py b/homeassistant/components/sensor/min_max.py index 9e36904222b..513b738bc36 100644 --- a/homeassistant/components/sensor/min_max.py +++ b/homeassistant/components/sensor/min_max.py @@ -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):