Add device classes to weather sensors. (#28512)
This commit is contained in:
parent
d7f45a47f5
commit
4bcc669d19
1 changed files with 29 additions and 14 deletions
|
@ -19,6 +19,11 @@ from homeassistant.const import (
|
||||||
CONF_MONITORED_CONDITIONS,
|
CONF_MONITORED_CONDITIONS,
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
CONF_NAME,
|
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.aiohttp_client import async_get_clientsession
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
@ -34,20 +39,24 @@ ATTRIBUTION = (
|
||||||
# https://api.met.no/license_data.html
|
# https://api.met.no/license_data.html
|
||||||
|
|
||||||
SENSOR_TYPES = {
|
SENSOR_TYPES = {
|
||||||
"symbol": ["Symbol", None],
|
"symbol": ["Symbol", None, None],
|
||||||
"precipitation": ["Precipitation", "mm"],
|
"precipitation": ["Precipitation", "mm", None],
|
||||||
"temperature": ["Temperature", "°C"],
|
"temperature": ["Temperature", TEMP_CELSIUS, DEVICE_CLASS_TEMPERATURE],
|
||||||
"windSpeed": ["Wind speed", "m/s"],
|
"windSpeed": ["Wind speed", "m/s", None],
|
||||||
"windGust": ["Wind gust", "m/s"],
|
"windGust": ["Wind gust", "m/s", None],
|
||||||
"pressure": ["Pressure", "hPa"],
|
"pressure": ["Pressure", PRESSURE_HPA, DEVICE_CLASS_PRESSURE],
|
||||||
"windDirection": ["Wind direction", "°"],
|
"windDirection": ["Wind direction", "°", None],
|
||||||
"humidity": ["Humidity", "%"],
|
"humidity": ["Humidity", "%", DEVICE_CLASS_HUMIDITY],
|
||||||
"fog": ["Fog", "%"],
|
"fog": ["Fog", "%", None],
|
||||||
"cloudiness": ["Cloudiness", "%"],
|
"cloudiness": ["Cloudiness", "%", None],
|
||||||
"lowClouds": ["Low clouds", "%"],
|
"lowClouds": ["Low clouds", "%", None],
|
||||||
"mediumClouds": ["Medium clouds", "%"],
|
"mediumClouds": ["Medium clouds", "%", None],
|
||||||
"highClouds": ["High clouds", "%"],
|
"highClouds": ["High clouds", "%", None],
|
||||||
"dewpointTemperature": ["Dewpoint temperature", "°C"],
|
"dewpointTemperature": [
|
||||||
|
"Dewpoint temperature",
|
||||||
|
TEMP_CELSIUS,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
CONF_FORECAST = "forecast"
|
CONF_FORECAST = "forecast"
|
||||||
|
@ -103,6 +112,7 @@ class YrSensor(Entity):
|
||||||
self.type = sensor_type
|
self.type = sensor_type
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
|
self._unit_of_measurement = SENSOR_TYPES[self.type][1]
|
||||||
|
self._device_class = SENSOR_TYPES[self.type][2]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
@ -139,6 +149,11 @@ class YrSensor(Entity):
|
||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
return self._unit_of_measurement
|
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:
|
class YrData:
|
||||||
"""Get the latest data and updates the states."""
|
"""Get the latest data and updates the states."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue