Add sensor device classes (#14010)
parent
8459b241a2
commit
2a5fac3b9d
|
@ -8,6 +8,8 @@ https://home-assistant.io/components/sensor/
|
|||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.config_validation import PLATFORM_SCHEMA # noqa
|
||||
|
||||
|
@ -18,6 +20,13 @@ DOMAIN = 'sensor'
|
|||
ENTITY_ID_FORMAT = DOMAIN + '.{}'
|
||||
|
||||
SCAN_INTERVAL = timedelta(seconds=30)
|
||||
DEVICE_CLASSES = [
|
||||
'battery', # % of battery that is left
|
||||
'humidity', # % of humidity in the air
|
||||
'temperature', # temperature (C/F)
|
||||
]
|
||||
|
||||
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES))
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
|
|
|
@ -52,6 +52,13 @@ class EcobeeSensor(Entity):
|
|||
"""Return the name of the Ecobee sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
if self.type in ('temperature', 'humidity'):
|
||||
return self.type
|
||||
return None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
|
|
|
@ -94,6 +94,11 @@ class LinuxBatterySensor(Entity):
|
|||
"""Return the name of the sensor."""
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return 'battery'
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the sensor."""
|
||||
|
|
|
@ -140,6 +140,11 @@ class NestTempSensor(NestSensor):
|
|||
"""Return the state of the sensor."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_class(self):
|
||||
"""Return the device class of the sensor."""
|
||||
return 'temperature'
|
||||
|
||||
def update(self):
|
||||
"""Retrieve latest state."""
|
||||
if self.device.temperature_scale == 'C':
|
||||
|
|
Loading…
Reference in New Issue