From 4bcc669d19521d061f0f2db28a366f0a0065ac83 Mon Sep 17 00:00:00 2001 From: Dave T <17680170+davet2001@users.noreply.github.com> Date: Wed, 13 Nov 2019 07:42:46 +0000 Subject: [PATCH] Add device classes to weather sensors. (#28512) --- homeassistant/components/yr/sensor.py | 43 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/homeassistant/components/yr/sensor.py b/homeassistant/components/yr/sensor.py index f562f519ab5..fc754c9a257 100644 --- a/homeassistant/components/yr/sensor.py +++ b/homeassistant/components/yr/sensor.py @@ -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.""" -- GitLab