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__)
|
_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):
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||||
"""Perform the setup for Xiaomi devices."""
|
"""Perform the setup for Xiaomi devices."""
|
||||||
|
@ -42,19 +50,21 @@ class XiaomiSensor(XiaomiDevice):
|
||||||
self._data_key = data_key
|
self._data_key = data_key
|
||||||
XiaomiDevice.__init__(self, device, name, xiaomi_hub)
|
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
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
if self._data_key == 'temperature':
|
try:
|
||||||
return TEMP_CELSIUS
|
return SENSOR_TYPES.get(self._data_key)[0]
|
||||||
elif self._data_key == 'humidity':
|
except TypeError:
|
||||||
return '%'
|
return None
|
||||||
elif self._data_key == 'illumination':
|
|
||||||
return 'lm'
|
|
||||||
elif self._data_key == 'lux':
|
|
||||||
return 'lx'
|
|
||||||
elif self._data_key == 'pressure':
|
|
||||||
return 'hPa'
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue