Add temperature device class to Darksky sensors (#35544)
This commit is contained in:
parent
befda9a78b
commit
1f71bdedab
2 changed files with 13 additions and 1 deletions
|
@ -6,7 +6,7 @@ import forecastio
|
||||||
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
|
from requests.exceptions import ConnectionError as ConnectError, HTTPError, Timeout
|
||||||
import voluptuous as vol
|
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 (
|
from homeassistant.const import (
|
||||||
ATTR_ATTRIBUTION,
|
ATTR_ATTRIBUTION,
|
||||||
CONF_API_KEY,
|
CONF_API_KEY,
|
||||||
|
@ -610,6 +610,14 @@ class DarkSkySensor(Entity):
|
||||||
|
|
||||||
return SENSOR_TYPES[self.type][6]
|
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
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|
|
@ -195,3 +195,7 @@ class TestDarkSkySetup(unittest.TestCase):
|
||||||
assert state.attributes.get("friendly_name") == "Dark Sky Summary"
|
assert state.attributes.get("friendly_name") == "Dark Sky Summary"
|
||||||
state = self.hass.states.get("sensor.dark_sky_alerts")
|
state = self.hass.states.get("sensor.dark_sky_alerts")
|
||||||
assert state.state == "2"
|
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"
|
||||||
|
|
Loading…
Add table
Reference in a new issue