diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index e0bf3c86b05..2bc35a034f4 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -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): diff --git a/homeassistant/components/sensor/ecobee.py b/homeassistant/components/sensor/ecobee.py index dad770d5bab..7274f421f15 100644 --- a/homeassistant/components/sensor/ecobee.py +++ b/homeassistant/components/sensor/ecobee.py @@ -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.""" diff --git a/homeassistant/components/sensor/linux_battery.py b/homeassistant/components/sensor/linux_battery.py index 3d28c44d606..1f0e3e89e5c 100644 --- a/homeassistant/components/sensor/linux_battery.py +++ b/homeassistant/components/sensor/linux_battery.py @@ -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.""" diff --git a/homeassistant/components/sensor/nest.py b/homeassistant/components/sensor/nest.py index e2567fdf4ca..5ee4f738051 100644 --- a/homeassistant/components/sensor/nest.py +++ b/homeassistant/components/sensor/nest.py @@ -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':