Add sensor_class to binary_sensor

This adds a 'sensor_class' property and attribute, which should be either
None or one of several defined SENSOR_CLASSES to indicate contextual
information about what the sensor is measuring.
This commit is contained in:
Dan Smith 2016-02-17 15:58:31 -08:00
parent 182fcb5f03
commit 2d932f89fc
2 changed files with 58 additions and 0 deletions

View file

@ -17,6 +17,17 @@ DOMAIN = 'binary_sensor'
SCAN_INTERVAL = 30
ENTITY_ID_FORMAT = DOMAIN + '.{}'
SENSOR_CLASSES = [
None, # Generic on/off
'opening', # Door, window, etc
'motion', # Motion sensor
'gas', # CO, CO2, etc
'smoke', # Smoke detector
'moisture', # Specifically a wetness sensor
'light', # Lightness threshold
'power', # Power, over-current, etc
'safety', # Generic on=unsafe, off=safe
]
def setup(hass, config):
@ -47,3 +58,14 @@ class BinarySensorDevice(Entity):
def friendly_state(self):
""" Returns the friendly state of the binary sensor. """
return None
@property
def sensor_class(self):
""" Returns the class of this sensor, from SENSOR_CASSES. """
return None
@property
def device_state_attributes(self):
return {
'sensor_class': self.sensor_class,
}