Set device_class on temperature sensors F-K (#52918)

* Set device_class on temperature sensors F-K

* Fix juicenet sensor
This commit is contained in:
Erik Montnemery 2021-07-12 20:32:55 +02:00 committed by GitHub
parent 646862ec96
commit 3e09787d85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 123 additions and 41 deletions

View file

@ -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."""