Set device_class on temperature sensors A-E (#49524)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Erik Montnemery 2021-07-12 22:45:29 +02:00 committed by GitHub
parent 0099b54489
commit 9b8a776001
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 593 additions and 258 deletions

View file

@ -29,6 +29,7 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
CONF_NAME,
DEGREE,
DEVICE_CLASS_TEMPERATURE,
IRRADIATION_WATTS_PER_SQUARE_METER,
LENGTH_KILOMETERS,
LENGTH_MILLIMETERS,
@ -60,132 +61,260 @@ SCHEDULE_NOK = 2
# Supported sensor types:
# Key: ['label', unit, icon]
SENSOR_TYPES = {
"stationname": ["Stationname", None, None],
"stationname": ["Stationname", None, None, None],
# new in json api (>1.0.0):
"barometerfc": ["Barometer value", None, "mdi:gauge"],
"barometerfc": ["Barometer value", None, "mdi:gauge", None],
# new in json api (>1.0.0):
"barometerfcname": ["Barometer", None, "mdi:gauge"],
"barometerfcname": ["Barometer", None, "mdi:gauge", None],
# new in json api (>1.0.0):
"barometerfcnamenl": ["Barometer", None, "mdi:gauge"],
"condition": ["Condition", None, None],
"conditioncode": ["Condition code", None, None],
"conditiondetailed": ["Detailed condition", None, None],
"conditionexact": ["Full condition", None, None],
"symbol": ["Symbol", None, None],
"barometerfcnamenl": ["Barometer", None, "mdi:gauge", None],
"condition": ["Condition", None, None, None],
"conditioncode": ["Condition code", None, None, None],
"conditiondetailed": ["Detailed condition", None, None, None],
"conditionexact": ["Full condition", None, None, None],
"symbol": ["Symbol", None, None, None],
# new in json api (>1.0.0):
"feeltemperature": ["Feel temperature", TEMP_CELSIUS, "mdi:thermometer"],
"humidity": ["Humidity", PERCENTAGE, "mdi:water-percent"],
"temperature": ["Temperature", TEMP_CELSIUS, "mdi:thermometer"],
"groundtemperature": ["Ground temperature", TEMP_CELSIUS, "mdi:thermometer"],
"windspeed": ["Wind speed", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windforce": ["Wind force", "Bft", "mdi:weather-windy"],
"winddirection": ["Wind direction", None, "mdi:compass-outline"],
"windazimuth": ["Wind direction azimuth", DEGREE, "mdi:compass-outline"],
"pressure": ["Pressure", PRESSURE_HPA, "mdi:gauge"],
"visibility": ["Visibility", LENGTH_KILOMETERS, None],
"windgust": ["Wind gust", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"feeltemperature": [
"Feel temperature",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"humidity": ["Humidity", PERCENTAGE, "mdi:water-percent", None],
"temperature": [
"Temperature",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"groundtemperature": [
"Ground temperature",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"windspeed": ["Wind speed", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy", None],
"windforce": ["Wind force", "Bft", "mdi:weather-windy", None],
"winddirection": ["Wind direction", None, "mdi:compass-outline", None],
"windazimuth": ["Wind direction azimuth", DEGREE, "mdi:compass-outline", None],
"pressure": ["Pressure", PRESSURE_HPA, "mdi:gauge", None],
"visibility": ["Visibility", LENGTH_KILOMETERS, None, None],
"windgust": ["Wind gust", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy", None],
"precipitation": [
"Precipitation",
PRECIPITATION_MILLIMETERS_PER_HOUR,
"mdi:weather-pouring",
None,
],
"irradiance": [
"Irradiance",
IRRADIATION_WATTS_PER_SQUARE_METER,
"mdi:sunglasses",
None,
],
"irradiance": ["Irradiance", IRRADIATION_WATTS_PER_SQUARE_METER, "mdi:sunglasses"],
"precipitation_forecast_average": [
"Precipitation forecast average",
PRECIPITATION_MILLIMETERS_PER_HOUR,
"mdi:weather-pouring",
None,
],
"precipitation_forecast_total": [
"Precipitation forecast total",
LENGTH_MILLIMETERS,
"mdi:weather-pouring",
None,
],
# new in json api (>1.0.0):
"rainlast24hour": ["Rain last 24h", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rainlast24hour": [
"Rain last 24h",
LENGTH_MILLIMETERS,
"mdi:weather-pouring",
None,
],
# new in json api (>1.0.0):
"rainlasthour": ["Rain last hour", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"temperature_1d": ["Temperature 1d", TEMP_CELSIUS, "mdi:thermometer"],
"temperature_2d": ["Temperature 2d", TEMP_CELSIUS, "mdi:thermometer"],
"temperature_3d": ["Temperature 3d", TEMP_CELSIUS, "mdi:thermometer"],
"temperature_4d": ["Temperature 4d", TEMP_CELSIUS, "mdi:thermometer"],
"temperature_5d": ["Temperature 5d", TEMP_CELSIUS, "mdi:thermometer"],
"mintemp_1d": ["Minimum temperature 1d", TEMP_CELSIUS, "mdi:thermometer"],
"mintemp_2d": ["Minimum temperature 2d", TEMP_CELSIUS, "mdi:thermometer"],
"mintemp_3d": ["Minimum temperature 3d", TEMP_CELSIUS, "mdi:thermometer"],
"mintemp_4d": ["Minimum temperature 4d", TEMP_CELSIUS, "mdi:thermometer"],
"mintemp_5d": ["Minimum temperature 5d", TEMP_CELSIUS, "mdi:thermometer"],
"rain_1d": ["Rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rain_2d": ["Rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rain_3d": ["Rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rain_4d": ["Rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rain_5d": ["Rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rainlasthour": ["Rain last hour", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"temperature_1d": [
"Temperature 1d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"temperature_2d": [
"Temperature 2d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"temperature_3d": [
"Temperature 3d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"temperature_4d": [
"Temperature 4d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"temperature_5d": [
"Temperature 5d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"mintemp_1d": [
"Minimum temperature 1d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"mintemp_2d": [
"Minimum temperature 2d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"mintemp_3d": [
"Minimum temperature 3d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"mintemp_4d": [
"Minimum temperature 4d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"mintemp_5d": [
"Minimum temperature 5d",
TEMP_CELSIUS,
None,
DEVICE_CLASS_TEMPERATURE,
],
"rain_1d": ["Rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"rain_2d": ["Rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"rain_3d": ["Rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"rain_4d": ["Rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"rain_5d": ["Rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
# new in json api (>1.0.0):
"minrain_1d": ["Minimum rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"minrain_2d": ["Minimum rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"minrain_3d": ["Minimum rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"minrain_4d": ["Minimum rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"minrain_5d": ["Minimum rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"minrain_1d": ["Minimum rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"minrain_2d": ["Minimum rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"minrain_3d": ["Minimum rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"minrain_4d": ["Minimum rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"minrain_5d": ["Minimum rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
# new in json api (>1.0.0):
"maxrain_1d": ["Maximum rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"maxrain_2d": ["Maximum rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"maxrain_3d": ["Maximum rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"maxrain_4d": ["Maximum rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"maxrain_5d": ["Maximum rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring"],
"rainchance_1d": ["Rainchance 1d", PERCENTAGE, "mdi:weather-pouring"],
"rainchance_2d": ["Rainchance 2d", PERCENTAGE, "mdi:weather-pouring"],
"rainchance_3d": ["Rainchance 3d", PERCENTAGE, "mdi:weather-pouring"],
"rainchance_4d": ["Rainchance 4d", PERCENTAGE, "mdi:weather-pouring"],
"rainchance_5d": ["Rainchance 5d", PERCENTAGE, "mdi:weather-pouring"],
"sunchance_1d": ["Sunchance 1d", PERCENTAGE, "mdi:weather-partly-cloudy"],
"sunchance_2d": ["Sunchance 2d", PERCENTAGE, "mdi:weather-partly-cloudy"],
"sunchance_3d": ["Sunchance 3d", PERCENTAGE, "mdi:weather-partly-cloudy"],
"sunchance_4d": ["Sunchance 4d", PERCENTAGE, "mdi:weather-partly-cloudy"],
"sunchance_5d": ["Sunchance 5d", PERCENTAGE, "mdi:weather-partly-cloudy"],
"windforce_1d": ["Wind force 1d", "Bft", "mdi:weather-windy"],
"windforce_2d": ["Wind force 2d", "Bft", "mdi:weather-windy"],
"windforce_3d": ["Wind force 3d", "Bft", "mdi:weather-windy"],
"windforce_4d": ["Wind force 4d", "Bft", "mdi:weather-windy"],
"windforce_5d": ["Wind force 5d", "Bft", "mdi:weather-windy"],
"windspeed_1d": ["Wind speed 1d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windspeed_2d": ["Wind speed 2d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windspeed_3d": ["Wind speed 3d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windspeed_4d": ["Wind speed 4d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"windspeed_5d": ["Wind speed 5d", SPEED_KILOMETERS_PER_HOUR, "mdi:weather-windy"],
"winddirection_1d": ["Wind direction 1d", None, "mdi:compass-outline"],
"winddirection_2d": ["Wind direction 2d", None, "mdi:compass-outline"],
"winddirection_3d": ["Wind direction 3d", None, "mdi:compass-outline"],
"winddirection_4d": ["Wind direction 4d", None, "mdi:compass-outline"],
"winddirection_5d": ["Wind direction 5d", None, "mdi:compass-outline"],
"windazimuth_1d": ["Wind direction azimuth 1d", DEGREE, "mdi:compass-outline"],
"windazimuth_2d": ["Wind direction azimuth 2d", DEGREE, "mdi:compass-outline"],
"windazimuth_3d": ["Wind direction azimuth 3d", DEGREE, "mdi:compass-outline"],
"windazimuth_4d": ["Wind direction azimuth 4d", DEGREE, "mdi:compass-outline"],
"windazimuth_5d": ["Wind direction azimuth 5d", DEGREE, "mdi:compass-outline"],
"condition_1d": ["Condition 1d", None, None],
"condition_2d": ["Condition 2d", None, None],
"condition_3d": ["Condition 3d", None, None],
"condition_4d": ["Condition 4d", None, None],
"condition_5d": ["Condition 5d", None, None],
"conditioncode_1d": ["Condition code 1d", None, None],
"conditioncode_2d": ["Condition code 2d", None, None],
"conditioncode_3d": ["Condition code 3d", None, None],
"conditioncode_4d": ["Condition code 4d", None, None],
"conditioncode_5d": ["Condition code 5d", None, None],
"conditiondetailed_1d": ["Detailed condition 1d", None, None],
"conditiondetailed_2d": ["Detailed condition 2d", None, None],
"conditiondetailed_3d": ["Detailed condition 3d", None, None],
"conditiondetailed_4d": ["Detailed condition 4d", None, None],
"conditiondetailed_5d": ["Detailed condition 5d", None, None],
"conditionexact_1d": ["Full condition 1d", None, None],
"conditionexact_2d": ["Full condition 2d", None, None],
"conditionexact_3d": ["Full condition 3d", None, None],
"conditionexact_4d": ["Full condition 4d", None, None],
"conditionexact_5d": ["Full condition 5d", None, None],
"symbol_1d": ["Symbol 1d", None, None],
"symbol_2d": ["Symbol 2d", None, None],
"symbol_3d": ["Symbol 3d", None, None],
"symbol_4d": ["Symbol 4d", None, None],
"symbol_5d": ["Symbol 5d", None, None],
"maxrain_1d": ["Maximum rain 1d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"maxrain_2d": ["Maximum rain 2d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"maxrain_3d": ["Maximum rain 3d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"maxrain_4d": ["Maximum rain 4d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"maxrain_5d": ["Maximum rain 5d", LENGTH_MILLIMETERS, "mdi:weather-pouring", None],
"rainchance_1d": ["Rainchance 1d", PERCENTAGE, "mdi:weather-pouring", None],
"rainchance_2d": ["Rainchance 2d", PERCENTAGE, "mdi:weather-pouring", None],
"rainchance_3d": ["Rainchance 3d", PERCENTAGE, "mdi:weather-pouring", None],
"rainchance_4d": ["Rainchance 4d", PERCENTAGE, "mdi:weather-pouring", None],
"rainchance_5d": ["Rainchance 5d", PERCENTAGE, "mdi:weather-pouring", None],
"sunchance_1d": ["Sunchance 1d", PERCENTAGE, "mdi:weather-partly-cloudy", None],
"sunchance_2d": ["Sunchance 2d", PERCENTAGE, "mdi:weather-partly-cloudy", None],
"sunchance_3d": ["Sunchance 3d", PERCENTAGE, "mdi:weather-partly-cloudy", None],
"sunchance_4d": ["Sunchance 4d", PERCENTAGE, "mdi:weather-partly-cloudy", None],
"sunchance_5d": ["Sunchance 5d", PERCENTAGE, "mdi:weather-partly-cloudy", None],
"windforce_1d": ["Wind force 1d", "Bft", "mdi:weather-windy", None],
"windforce_2d": ["Wind force 2d", "Bft", "mdi:weather-windy", None],
"windforce_3d": ["Wind force 3d", "Bft", "mdi:weather-windy", None],
"windforce_4d": ["Wind force 4d", "Bft", "mdi:weather-windy", None],
"windforce_5d": ["Wind force 5d", "Bft", "mdi:weather-windy", None],
"windspeed_1d": [
"Wind speed 1d",
SPEED_KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
"windspeed_2d": [
"Wind speed 2d",
SPEED_KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
"windspeed_3d": [
"Wind speed 3d",
SPEED_KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
"windspeed_4d": [
"Wind speed 4d",
SPEED_KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
"windspeed_5d": [
"Wind speed 5d",
SPEED_KILOMETERS_PER_HOUR,
"mdi:weather-windy",
None,
],
"winddirection_1d": ["Wind direction 1d", None, "mdi:compass-outline", None],
"winddirection_2d": ["Wind direction 2d", None, "mdi:compass-outline", None],
"winddirection_3d": ["Wind direction 3d", None, "mdi:compass-outline", None],
"winddirection_4d": ["Wind direction 4d", None, "mdi:compass-outline", None],
"winddirection_5d": ["Wind direction 5d", None, "mdi:compass-outline", None],
"windazimuth_1d": [
"Wind direction azimuth 1d",
DEGREE,
"mdi:compass-outline",
None,
],
"windazimuth_2d": [
"Wind direction azimuth 2d",
DEGREE,
"mdi:compass-outline",
None,
],
"windazimuth_3d": [
"Wind direction azimuth 3d",
DEGREE,
"mdi:compass-outline",
None,
],
"windazimuth_4d": [
"Wind direction azimuth 4d",
DEGREE,
"mdi:compass-outline",
None,
],
"windazimuth_5d": [
"Wind direction azimuth 5d",
DEGREE,
"mdi:compass-outline",
None,
],
"condition_1d": ["Condition 1d", None, None, None],
"condition_2d": ["Condition 2d", None, None, None],
"condition_3d": ["Condition 3d", None, None, None],
"condition_4d": ["Condition 4d", None, None, None],
"condition_5d": ["Condition 5d", None, None, None],
"conditioncode_1d": ["Condition code 1d", None, None, None],
"conditioncode_2d": ["Condition code 2d", None, None, None],
"conditioncode_3d": ["Condition code 3d", None, None, None],
"conditioncode_4d": ["Condition code 4d", None, None, None],
"conditioncode_5d": ["Condition code 5d", None, None, None],
"conditiondetailed_1d": ["Detailed condition 1d", None, None, None],
"conditiondetailed_2d": ["Detailed condition 2d", None, None, None],
"conditiondetailed_3d": ["Detailed condition 3d", None, None, None],
"conditiondetailed_4d": ["Detailed condition 4d", None, None, None],
"conditiondetailed_5d": ["Detailed condition 5d", None, None, None],
"conditionexact_1d": ["Full condition 1d", None, None, None],
"conditionexact_2d": ["Full condition 2d", None, None, None],
"conditionexact_3d": ["Full condition 3d", None, None, None],
"conditionexact_4d": ["Full condition 4d", None, None, None],
"conditionexact_5d": ["Full condition 5d", None, None, None],
"symbol_1d": ["Symbol 1d", None, None, None],
"symbol_2d": ["Symbol 2d", None, None, None],
"symbol_3d": ["Symbol 3d", None, None, None],
"symbol_4d": ["Symbol 4d", None, None, None],
"symbol_5d": ["Symbol 5d", None, None, None],
}
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
@ -471,6 +600,11 @@ class BrSensor(SensorEntity):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@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):
"""Return possible sensor specific icon."""