diff --git a/homeassistant/components/foobot/sensor.py b/homeassistant/components/foobot/sensor.py index 996ac1b1049..d635f231818 100644 --- a/homeassistant/components/foobot/sensor.py +++ b/homeassistant/components/foobot/sensor.py @@ -16,6 +16,7 @@ from homeassistant.const import ( CONCENTRATION_PARTS_PER_MILLION, CONF_TOKEN, CONF_USERNAME, + DEVICE_CLASS_TEMPERATURE, PERCENTAGE, TEMP_CELSIUS, TIME_SECONDS, @@ -36,17 +37,23 @@ ATTR_VOLATILE_ORGANIC_COMPOUNDS = "VOC" ATTR_FOOBOT_INDEX = "index" SENSOR_TYPES = { - "time": [ATTR_TIME, TIME_SECONDS], - "pm": [ATTR_PM2_5, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, "mdi:cloud"], - "tmp": [ATTR_TEMPERATURE, TEMP_CELSIUS, "mdi:thermometer"], - "hum": [ATTR_HUMIDITY, PERCENTAGE, "mdi:water-percent"], - "co2": [ATTR_CARBON_DIOXIDE, CONCENTRATION_PARTS_PER_MILLION, "mdi:molecule-co2"], + "time": [ATTR_TIME, TIME_SECONDS, None, None], + "pm": [ATTR_PM2_5, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER, "mdi:cloud", None], + "tmp": [ATTR_TEMPERATURE, TEMP_CELSIUS, None, DEVICE_CLASS_TEMPERATURE], + "hum": [ATTR_HUMIDITY, PERCENTAGE, "mdi:water-percent", None], + "co2": [ + ATTR_CARBON_DIOXIDE, + CONCENTRATION_PARTS_PER_MILLION, + "mdi:molecule-co2", + None, + ], "voc": [ ATTR_VOLATILE_ORGANIC_COMPOUNDS, CONCENTRATION_PARTS_PER_BILLION, "mdi:cloud", + None, ], - "allpollu": [ATTR_FOOBOT_INDEX, PERCENTAGE, "mdi:percent"], + "allpollu": [ATTR_FOOBOT_INDEX, PERCENTAGE, "mdi:percent", None], } SCAN_INTERVAL = timedelta(minutes=10) @@ -108,6 +115,11 @@ class FoobotSensor(SensorEntity): """Return the name of the sensor.""" return self._name + @property + def device_class(self): + """Return the class of this device, from component DEVICE_CLASSES.""" + return SENSOR_TYPES[self.type][3] + @property def icon(self): """Icon to use in the frontend.""" diff --git a/homeassistant/components/fritzbox/sensor.py b/homeassistant/components/fritzbox/sensor.py index ceae0bb757f..db50776d69c 100644 --- a/homeassistant/components/fritzbox/sensor.py +++ b/homeassistant/components/fritzbox/sensor.py @@ -9,6 +9,7 @@ from homeassistant.const import ( ATTR_NAME, ATTR_UNIT_OF_MEASUREMENT, DEVICE_CLASS_BATTERY, + DEVICE_CLASS_TEMPERATURE, PERCENTAGE, TEMP_CELSIUS, ) @@ -44,7 +45,7 @@ async def async_setup_entry( ATTR_NAME: f"{device.name}", ATTR_ENTITY_ID: f"{device.ain}", ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS, - ATTR_DEVICE_CLASS: None, + ATTR_DEVICE_CLASS: DEVICE_CLASS_TEMPERATURE, }, coordinator, ain, diff --git a/homeassistant/components/glances/const.py b/homeassistant/components/glances/const.py index 18865a232d7..8e20fbfa46b 100644 --- a/homeassistant/components/glances/const.py +++ b/homeassistant/components/glances/const.py @@ -1,7 +1,13 @@ """Constants for Glances component.""" import sys -from homeassistant.const import DATA_GIBIBYTES, DATA_MEBIBYTES, PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import ( + DATA_GIBIBYTES, + DATA_MEBIBYTES, + DEVICE_CLASS_TEMPERATURE, + PERCENTAGE, + TEMP_CELSIUS, +) DOMAIN = "glances" CONF_VERSION = "version" @@ -21,31 +27,50 @@ else: CPU_ICON = "mdi:cpu-32-bit" SENSOR_TYPES = { - "disk_use_percent": ["fs", "used percent", PERCENTAGE, "mdi:harddisk"], - "disk_use": ["fs", "used", DATA_GIBIBYTES, "mdi:harddisk"], - "disk_free": ["fs", "free", DATA_GIBIBYTES, "mdi:harddisk"], - "memory_use_percent": ["mem", "RAM used percent", PERCENTAGE, "mdi:memory"], - "memory_use": ["mem", "RAM used", DATA_MEBIBYTES, "mdi:memory"], - "memory_free": ["mem", "RAM free", DATA_MEBIBYTES, "mdi:memory"], - "swap_use_percent": ["memswap", "Swap used percent", PERCENTAGE, "mdi:memory"], - "swap_use": ["memswap", "Swap used", DATA_GIBIBYTES, "mdi:memory"], - "swap_free": ["memswap", "Swap free", DATA_GIBIBYTES, "mdi:memory"], - "processor_load": ["load", "CPU load", "15 min", CPU_ICON], - "process_running": ["processcount", "Running", "Count", CPU_ICON], - "process_total": ["processcount", "Total", "Count", CPU_ICON], - "process_thread": ["processcount", "Thread", "Count", CPU_ICON], - "process_sleeping": ["processcount", "Sleeping", "Count", CPU_ICON], - "cpu_use_percent": ["cpu", "CPU used", PERCENTAGE, CPU_ICON], - "temperature_core": ["sensors", "Temperature", TEMP_CELSIUS, "mdi:thermometer"], - "temperature_hdd": ["sensors", "Temperature", TEMP_CELSIUS, "mdi:thermometer"], - "fan_speed": ["sensors", "Fan speed", "RPM", "mdi:fan"], - "battery": ["sensors", "Charge", PERCENTAGE, "mdi:battery"], - "docker_active": ["docker", "Containers active", "", "mdi:docker"], - "docker_cpu_use": ["docker", "Containers CPU used", PERCENTAGE, "mdi:docker"], + "disk_use_percent": ["fs", "used percent", PERCENTAGE, "mdi:harddisk", None], + "disk_use": ["fs", "used", DATA_GIBIBYTES, "mdi:harddisk", None], + "disk_free": ["fs", "free", DATA_GIBIBYTES, "mdi:harddisk", None], + "memory_use_percent": ["mem", "RAM used percent", PERCENTAGE, "mdi:memory", None], + "memory_use": ["mem", "RAM used", DATA_MEBIBYTES, "mdi:memory", None], + "memory_free": ["mem", "RAM free", DATA_MEBIBYTES, "mdi:memory", None], + "swap_use_percent": [ + "memswap", + "Swap used percent", + PERCENTAGE, + "mdi:memory", + None, + ], + "swap_use": ["memswap", "Swap used", DATA_GIBIBYTES, "mdi:memory", None], + "swap_free": ["memswap", "Swap free", DATA_GIBIBYTES, "mdi:memory", None], + "processor_load": ["load", "CPU load", "15 min", CPU_ICON, None], + "process_running": ["processcount", "Running", "Count", CPU_ICON, None], + "process_total": ["processcount", "Total", "Count", CPU_ICON, None], + "process_thread": ["processcount", "Thread", "Count", CPU_ICON, None], + "process_sleeping": ["processcount", "Sleeping", "Count", CPU_ICON, None], + "cpu_use_percent": ["cpu", "CPU used", PERCENTAGE, CPU_ICON, None], + "temperature_core": [ + "sensors", + "Temperature", + TEMP_CELSIUS, + None, + DEVICE_CLASS_TEMPERATURE, + ], + "temperature_hdd": [ + "sensors", + "Temperature", + TEMP_CELSIUS, + None, + DEVICE_CLASS_TEMPERATURE, + ], + "fan_speed": ["sensors", "Fan speed", "RPM", "mdi:fan", None], + "battery": ["sensors", "Charge", PERCENTAGE, "mdi:battery", None], + "docker_active": ["docker", "Containers active", "", "mdi:docker", None], + "docker_cpu_use": ["docker", "Containers CPU used", PERCENTAGE, "mdi:docker", None], "docker_memory_use": [ "docker", "Containers RAM used", DATA_MEBIBYTES, "mdi:docker", + None, ], } diff --git a/homeassistant/components/glances/sensor.py b/homeassistant/components/glances/sensor.py index 7e599af414c..8306543f700 100644 --- a/homeassistant/components/glances/sensor.py +++ b/homeassistant/components/glances/sensor.py @@ -91,6 +91,11 @@ class GlancesSensor(SensorEntity): """Set unique_id for sensor.""" return f"{self.glances_data.host}-{self.name}" + @property + def device_class(self): + """Return the class of this device, from component DEVICE_CLASSES.""" + return self.sensor_details[4] + @property def icon(self): """Icon to use in the frontend, if any.""" diff --git a/homeassistant/components/hddtemp/sensor.py b/homeassistant/components/hddtemp/sensor.py index 4376c7f1289..8169fa811e0 100644 --- a/homeassistant/components/hddtemp/sensor.py +++ b/homeassistant/components/hddtemp/sensor.py @@ -12,6 +12,7 @@ from homeassistant.const import ( CONF_HOST, CONF_NAME, CONF_PORT, + DEVICE_CLASS_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT, ) @@ -81,6 +82,11 @@ class HddTempSensor(SensorEntity): """Return the state of the device.""" return self._state + @property + def device_class(self): + """Return the class of this device, from component DEVICE_CLASSES.""" + return DEVICE_CLASS_TEMPERATURE + @property def unit_of_measurement(self): """Return the unit the value is expressed in.""" diff --git a/homeassistant/components/ihc/sensor.py b/homeassistant/components/ihc/sensor.py index 3348e857f51..d1aec781df7 100644 --- a/homeassistant/components/ihc/sensor.py +++ b/homeassistant/components/ihc/sensor.py @@ -1,6 +1,7 @@ """Support for IHC sensors.""" from homeassistant.components.sensor import SensorEntity -from homeassistant.const import CONF_UNIT_OF_MEASUREMENT +from homeassistant.const import CONF_UNIT_OF_MEASUREMENT, DEVICE_CLASS_TEMPERATURE +from homeassistant.util.unit_system import TEMPERATURE_UNITS from . import IHC_CONTROLLER, IHC_INFO from .ihcdevice import IHCDevice @@ -37,6 +38,15 @@ class IHCSensor(IHCDevice, SensorEntity): self._state = None self._unit_of_measurement = unit + @property + def device_class(self): + """Return the class of this device, from component DEVICE_CLASSES.""" + return ( + DEVICE_CLASS_TEMPERATURE + if self._unit_of_measurement in TEMPERATURE_UNITS + else None + ) + @property def state(self): """Return the state of the sensor.""" diff --git a/homeassistant/components/juicenet/sensor.py b/homeassistant/components/juicenet/sensor.py index 7564c6e4344..81fabf17eea 100644 --- a/homeassistant/components/juicenet/sensor.py +++ b/homeassistant/components/juicenet/sensor.py @@ -1,6 +1,11 @@ """Support for monitoring juicenet/juicepoint/juicebox based EVSE sensors.""" from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.const import ( + DEVICE_CLASS_CURRENT, + DEVICE_CLASS_ENERGY, + DEVICE_CLASS_POWER, + DEVICE_CLASS_TEMPERATURE, + DEVICE_CLASS_VOLTAGE, ELECTRICAL_CURRENT_AMPERE, ENERGY_WATT_HOUR, POWER_WATT, @@ -13,13 +18,23 @@ from .const import DOMAIN, JUICENET_API, JUICENET_COORDINATOR from .entity import JuiceNetDevice SENSOR_TYPES = { - "status": ["Charging Status", None, None], - "temperature": ["Temperature", TEMP_CELSIUS, STATE_CLASS_MEASUREMENT], - "voltage": ["Voltage", VOLT, None], - "amps": ["Amps", ELECTRICAL_CURRENT_AMPERE, STATE_CLASS_MEASUREMENT], - "watts": ["Watts", POWER_WATT, STATE_CLASS_MEASUREMENT], - "charge_time": ["Charge time", TIME_SECONDS, None], - "energy_added": ["Energy added", ENERGY_WATT_HOUR, None], + "status": ["Charging Status", None, None, None], + "temperature": [ + "Temperature", + TEMP_CELSIUS, + DEVICE_CLASS_TEMPERATURE, + STATE_CLASS_MEASUREMENT, + ], + "voltage": ["Voltage", VOLT, DEVICE_CLASS_VOLTAGE, None], + "amps": [ + "Amps", + ELECTRICAL_CURRENT_AMPERE, + DEVICE_CLASS_CURRENT, + STATE_CLASS_MEASUREMENT, + ], + "watts": ["Watts", POWER_WATT, DEVICE_CLASS_POWER, STATE_CLASS_MEASUREMENT], + "charge_time": ["Charge time", TIME_SECONDS, None, None], + "energy_added": ["Energy added", ENERGY_WATT_HOUR, DEVICE_CLASS_ENERGY, None], } @@ -44,7 +59,8 @@ class JuiceNetSensorDevice(JuiceNetDevice, SensorEntity): super().__init__(device, sensor_type, coordinator) self._name = SENSOR_TYPES[sensor_type][0] self._unit_of_measurement = SENSOR_TYPES[sensor_type][1] - self._attr_state_class = SENSOR_TYPES[sensor_type][2] + self._attr_device_class = SENSOR_TYPES[sensor_type][2] + self._attr_state_class = SENSOR_TYPES[sensor_type][3] @property def name(self): diff --git a/homeassistant/components/kaiterra/sensor.py b/homeassistant/components/kaiterra/sensor.py index 1e4dd0cbbca..6c82013361a 100644 --- a/homeassistant/components/kaiterra/sensor.py +++ b/homeassistant/components/kaiterra/sensor.py @@ -1,13 +1,20 @@ """Support for Kaiterra Temperature ahn Humidity Sensors.""" from homeassistant.components.sensor import SensorEntity -from homeassistant.const import CONF_DEVICE_ID, CONF_NAME, TEMP_CELSIUS, TEMP_FAHRENHEIT +from homeassistant.const import ( + CONF_DEVICE_ID, + CONF_NAME, + DEVICE_CLASS_HUMIDITY, + DEVICE_CLASS_TEMPERATURE, + TEMP_CELSIUS, + TEMP_FAHRENHEIT, +) from homeassistant.helpers.dispatcher import async_dispatcher_connect from .const import DISPATCHER_KAITERRA, DOMAIN SENSORS = [ - {"name": "Temperature", "prop": "rtemp", "device_class": "temperature"}, - {"name": "Humidity", "prop": "rhumid", "device_class": "humidity"}, + {"name": "Temperature", "prop": "rtemp", "device_class": DEVICE_CLASS_TEMPERATURE}, + {"name": "Humidity", "prop": "rhumid", "device_class": DEVICE_CLASS_HUMIDITY}, ]