Add icons to Xiaomi Aqara sensors (#12814)
* Update xiaomi_aqara.py * Update xiaomi_aqara.py
This commit is contained in:
parent
03970764d8
commit
25c4c9b63c
1 changed files with 20 additions and 10 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Reference in a new issue