Add temperature device class to Darksky sensors (#35544)

This commit is contained in:
Paulus Schoutsen 2020-05-12 10:37:04 -07:00 committed by GitHub
parent befda9a78b
commit 1f71bdedab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -6,7 +6,7 @@ import forecastio
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
import voluptuous as vol
from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.components.sensor import DEVICE_CLASS_TEMPERATURE, PLATFORM_SCHEMA
from homeassistant.const import (
ATTR_ATTRIBUTION,
CONF_API_KEY,
@ -610,6 +610,14 @@ class DarkSkySensor(Entity):
return SENSOR_TYPES[self.type][6]
@property
def device_class(self):
"""Device class of the entity."""
if SENSOR_TYPES[self.type][1] == TEMP_CELSIUS:
return DEVICE_CLASS_TEMPERATURE
return None
@property
def device_state_attributes(self):
"""Return the state attributes."""

View file

@ -195,3 +195,7 @@ class TestDarkSkySetup(unittest.TestCase):
assert state.attributes.get("friendly_name") == "Dark Sky Summary"
state = self.hass.states.get("sensor.dark_sky_alerts")
assert state.state == "2"
state = self.hass.states.get("sensor.dark_sky_daytime_high_temperature_1d")
assert state is not None
assert state.attributes.get("device_class") == "temperature"