From 2443f5d108330469538900235d2046810e850d77 Mon Sep 17 00:00:00 2001 From: marecabo <23156476+marecabo@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:25:26 +0200 Subject: [PATCH] Add device classes to battery, illuminance and temperature miflora sensor (#41975) --- homeassistant/components/miflora/sensor.py | 24 ++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/miflora/sensor.py b/homeassistant/components/miflora/sensor.py index 5c5257d4181..6583f5f7e0c 100644 --- a/homeassistant/components/miflora/sensor.py +++ b/homeassistant/components/miflora/sensor.py @@ -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."""