Add device classes to battery, illuminance and temperature miflora sensor (#41975)
parent
5d1b4f5c87
commit
2443f5d108
|
@ -16,6 +16,9 @@ from homeassistant.const import (
|
|||
CONF_MONITORED_CONDITIONS,
|
||||
CONF_NAME,
|
||||
CONF_SCAN_INTERVAL,
|
||||
DEVICE_CLASS_BATTERY,
|
||||
DEVICE_CLASS_ILLUMINANCE,
|
||||
DEVICE_CLASS_TEMPERATURE,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
LIGHT_LUX,
|
||||
PERCENTAGE,
|
||||
|
@ -51,13 +54,13 @@ SCAN_INTERVAL = timedelta(seconds=1200)
|
|||
|
||||
ATTR_LAST_SUCCESSFUL_UPDATE = "last_successful_update"
|
||||
|
||||
# Sensor types are defined like: Name, units, icon
|
||||
# Sensor types are defined like: Name, units, icon, device_class
|
||||
SENSOR_TYPES = {
|
||||
"temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
|
||||
"light": ["Light intensity", LIGHT_LUX, "mdi:white-balance-sunny"],
|
||||
"moisture": ["Moisture", PERCENTAGE, "mdi:water-percent"],
|
||||
"conductivity": ["Conductivity", CONDUCTIVITY, "mdi:flash-circle"],
|
||||
"battery": ["Battery", PERCENTAGE, "mdi:battery-charging"],
|
||||
"temperature": ["Temperature", TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
|
||||
"light": ["Light intensity", LIGHT_LUX, None, DEVICE_CLASS_ILLUMINANCE],
|
||||
"moisture": ["Moisture", PERCENTAGE, "mdi:water-percent", None],
|
||||
"conductivity": ["Conductivity", CONDUCTIVITY, "mdi:flash-circle", None],
|
||||
"battery": ["Battery", PERCENTAGE, None, DEVICE_CLASS_BATTERY],
|
||||
}
|
||||
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
|
@ -104,6 +107,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
else SENSOR_TYPES[parameter][1]
|
||||
)
|
||||
icon = SENSOR_TYPES[parameter][2]
|
||||
device_class = SENSOR_TYPES[parameter][3]
|
||||
|
||||
prefix = config.get(CONF_NAME)
|
||||
if prefix:
|
||||
|
@ -116,6 +120,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
name,
|
||||
unit,
|
||||
icon,
|
||||
device_class,
|
||||
force_update,
|
||||
median,
|
||||
go_unavailable_timeout,
|
||||
|
@ -135,6 +140,7 @@ class MiFloraSensor(Entity):
|
|||
name,
|
||||
unit,
|
||||
icon,
|
||||
device_class,
|
||||
force_update,
|
||||
median,
|
||||
go_unavailable_timeout,
|
||||
|
@ -146,6 +152,7 @@ class MiFloraSensor(Entity):
|
|||
self._icon = icon
|
||||
self._name = name
|
||||
self._state = None
|
||||
self._device_class = device_class
|
||||
self.data = []
|
||||
self._force_update = force_update
|
||||
self.go_unavailable_timeout = go_unavailable_timeout
|
||||
|
@ -186,6 +193,11 @@ class MiFloraSensor(Entity):
|
|||
"""Return the state attributes of the device."""
|
||||
return {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class."""
|
||||
return self._device_class
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the units of measurement."""
|
||||
|
|
Loading…
Reference in New Issue