hass-core/homeassistant/components/binary_sensor/demo.py

44 lines
1.1 KiB
Python
Raw Normal View History

2015-11-19 19:00:22 +01:00
"""
homeassistant.components.binary_sensor.demo
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Demo platform that has two fake binary sensors.
"""
from homeassistant.components.binary_sensor import BinarySensorDevice
def setup_platform(hass, config, add_devices, discovery_info=None):
""" Sets up the Demo binary sensors. """
add_devices([
DemoBinarySensor('Basement Floor Wet', False, 'moisture'),
DemoBinarySensor('Movement Backyard', True, 'motion'),
2015-11-19 19:00:22 +01:00
])
class DemoBinarySensor(BinarySensorDevice):
""" A Demo binary sensor. """
def __init__(self, name, state, sensor_class):
2015-11-20 14:58:49 +01:00
self._name = name
2015-11-19 19:00:22 +01:00
self._state = state
self._sensor_type = sensor_class
@property
def sensor_class(self):
""" Return our class. """
return self._sensor_type
2015-11-19 19:00:22 +01:00
@property
def should_poll(self):
""" No polling needed for a demo binary sensor. """
return False
@property
def name(self):
""" Returns the name of the binary sensor. """
return self._name
@property
def is_on(self):
2015-11-20 14:58:49 +01:00
""" True if the binary sensor is on. """
2015-11-19 19:00:22 +01:00
return self._state