diff --git a/homeassistant/components/sensor/xiaomi_aqara.py b/homeassistant/components/sensor/xiaomi_aqara.py index c2498d88822..aed8c370a1c 100644 --- a/homeassistant/components/sensor/xiaomi_aqara.py +++ b/homeassistant/components/sensor/xiaomi_aqara.py @@ -7,6 +7,14 @@ from homeassistant.const import TEMP_CELSIUS _LOGGER = logging.getLogger(__name__) +SENSOR_TYPES = { + 'temperature': [TEMP_CELSIUS, 'mdi:thermometer'], + 'humidity': ['%', 'mdi:water-percent'], + 'illumination': ['lm'], + 'lux': ['lx'], + 'pressure': ['hPa', 'mdi:gauge'] +} + def setup_platform(hass, config, add_devices, discovery_info=None): """Perform the setup for Xiaomi devices.""" @@ -42,19 +50,21 @@ class XiaomiSensor(XiaomiDevice): self._data_key = data_key XiaomiDevice.__init__(self, device, name, xiaomi_hub) + @property + def icon(self): + """Return the icon to use in the frontend.""" + try: + return SENSOR_TYPES.get(self._data_key)[1] + except TypeError: + return None + @property def unit_of_measurement(self): """Return the unit of measurement of this entity, if any.""" - if self._data_key == 'temperature': - return TEMP_CELSIUS - elif self._data_key == 'humidity': - return '%' - elif self._data_key == 'illumination': - return 'lm' - elif self._data_key == 'lux': - return 'lx' - elif self._data_key == 'pressure': - return 'hPa' + try: + return SENSOR_TYPES.get(self._data_key)[0] + except TypeError: + return None @property def state(self):