Add device classes to weather sensors. (#28512)

This commit is contained in:
Dave T 2019-11-13 07:42:46 +00:00 committed by Fabian Affolter
parent d7f45a47f5
commit 4bcc669d19

View file

@ -19,6 +19,11 @@ from homeassistant.const import (
CONF_MONITORED_CONDITIONS,
ATTR_ATTRIBUTION,
CONF_NAME,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_PRESSURE,
DEVICE_CLASS_TEMPERATURE,
PRESSURE_HPA,
TEMP_CELSIUS,
)
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.entity import Entity
@ -34,20 +39,24 @@ ATTRIBUTION = (
# https://api.met.no/license_data.html
SENSOR_TYPES = {
"symbol": ["Symbol", None],
"precipitation": ["Precipitation", "mm"],
"temperature": ["Temperature", "°C"],
"windSpeed": ["Wind speed", "m/s"],
"windGust": ["Wind gust", "m/s"],
"pressure": ["Pressure", "hPa"],
"windDirection": ["Wind direction", "°"],
"humidity": ["Humidity", "%"],
"fog": ["Fog", "%"],
"cloudiness": ["Cloudiness", "%"],
"lowClouds": ["Low clouds", "%"],
"mediumClouds": ["Medium clouds", "%"],
"highClouds": ["High clouds", "%"],
"dewpointTemperature": ["Dewpoint temperature", "°C"],
"symbol": ["Symbol", None, None],
"precipitation": ["Precipitation", "mm", None],
"temperature": ["Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
"windSpeed": ["Wind speed", "m/s", None],
"windGust": ["Wind gust", "m/s", None],
"pressure": ["Pressure", PRESSURE_HPA, DEVICE_CLASS_PRESSURE],
"windDirection": ["Wind direction", "°", None],
"humidity": ["Humidity", "%", DEVICE_CLASS_HUMIDITY],
"fog": ["Fog", "%", None],
"cloudiness": ["Cloudiness", "%", None],
"lowClouds": ["Low clouds", "%", None],
"mediumClouds": ["Medium clouds", "%", None],
"highClouds": ["High clouds", "%", None],
"dewpointTemperature": [
"Dewpoint temperature",
TEMP_CELSIUS,
DEVICE_CLASS_TEMPERATURE,
],
}
CONF_FORECAST = "forecast"
@ -103,6 +112,7 @@ class YrSensor(Entity):
self.type = sensor_type
self._state = None
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
self._device_class = SENSOR_TYPES[self.type][2]
@property
def name(self):
@ -139,6 +149,11 @@ class YrSensor(Entity):
"""Return the unit of measurement of this entity, if any."""
return self._unit_of_measurement
@property
def device_class(self):
"""Return the device class of this entity, if any."""
return self._device_class
class YrData:
"""Get the latest data and updates the states."""