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_MONITORED_CONDITIONS,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_ILLUMINANCE,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
|
@ -51,13 +54,13 @@ SCAN_INTERVAL = timedelta(seconds=1200)
|
||||||
|
|
||||||
ATTR_LAST_SUCCESSFUL_UPDATE = "last_successful_update"
|
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 = {
|
SENSOR_TYPES = {
|
||||||
"temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
|
"temperature": ["Temperature", TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE],
|
||||||
"light": ["Light intensity", LIGHT_LUX, "mdi:white-balance-sunny"],
|
"light": ["Light intensity", LIGHT_LUX, None, DEVICE_CLASS_ILLUMINANCE],
|
||||||
"moisture": ["Moisture", PERCENTAGE, "mdi:water-percent"],
|
"moisture": ["Moisture", PERCENTAGE, "mdi:water-percent", None],
|
||||||
"conductivity": ["Conductivity", CONDUCTIVITY, "mdi:flash-circle"],
|
"conductivity": ["Conductivity", CONDUCTIVITY, "mdi:flash-circle", None],
|
||||||
"battery": ["Battery", PERCENTAGE, "mdi:battery-charging"],
|
"battery": ["Battery", PERCENTAGE, None, DEVICE_CLASS_BATTERY],
|
||||||
}
|
}
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
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]
|
else SENSOR_TYPES[parameter][1]
|
||||||
)
|
)
|
||||||
icon = SENSOR_TYPES[parameter][2]
|
icon = SENSOR_TYPES[parameter][2]
|
||||||
|
device_class = SENSOR_TYPES[parameter][3]
|
||||||
|
|
||||||
prefix = config.get(CONF_NAME)
|
prefix = config.get(CONF_NAME)
|
||||||
if prefix:
|
if prefix:
|
||||||
|
@ -116,6 +120,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
||||||
name,
|
name,
|
||||||
unit,
|
unit,
|
||||||
icon,
|
icon,
|
||||||
|
device_class,
|
||||||
force_update,
|
force_update,
|
||||||
median,
|
median,
|
||||||
go_unavailable_timeout,
|
go_unavailable_timeout,
|
||||||
|
@ -135,6 +140,7 @@ class MiFloraSensor(Entity):
|
||||||
name,
|
name,
|
||||||
unit,
|
unit,
|
||||||
icon,
|
icon,
|
||||||
|
device_class,
|
||||||
force_update,
|
force_update,
|
||||||
median,
|
median,
|
||||||
go_unavailable_timeout,
|
go_unavailable_timeout,
|
||||||
|
@ -146,6 +152,7 @@ class MiFloraSensor(Entity):
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
self._name = name
|
self._name = name
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._device_class = device_class
|
||||||
self.data = []
|
self.data = []
|
||||||
self._force_update = force_update
|
self._force_update = force_update
|
||||||
self.go_unavailable_timeout = go_unavailable_timeout
|
self.go_unavailable_timeout = go_unavailable_timeout
|
||||||
|
@ -186,6 +193,11 @@ class MiFloraSensor(Entity):
|
||||||
"""Return the state attributes of the device."""
|
"""Return the state attributes of the device."""
|
||||||
return {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
|
return {ATTR_LAST_SUCCESSFUL_UPDATE: self.last_successful_update}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device class."""
|
||||||
|
return self._device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the units of measurement."""
|
"""Return the units of measurement."""
|
||||||
|
|
Loading…
Reference in New Issue