core/homeassistant/components/binary_sensor/demo.py

46 lines
1.2 KiB
Python
Raw Normal View History

2015-11-19 18:00:22 +00:00
"""
Demo platform that has two fake binary sensors.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
2015-11-19 18:00:22 +00:00
"""
from homeassistant.components.binary_sensor import BinarySensorDevice
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Demo binary sensor platform."""
2015-11-19 18:00:22 +00:00
add_devices([
DemoBinarySensor('Basement Floor Wet', False, 'moisture'),
DemoBinarySensor('Movement Backyard', True, 'motion'),
2015-11-19 18:00:22 +00:00
])
class DemoBinarySensor(BinarySensorDevice):
"""representation of a Demo binary sensor."""
2016-03-07 19:21:08 +00:00
def __init__(self, name, state, device_class):
2016-03-07 19:21:08 +00:00
"""Initialize the demo sensor."""
2015-11-20 13:58:49 +00:00
self._name = name
2015-11-19 18:00:22 +00:00
self._state = state
self._sensor_type = device_class
@property
def device_class(self):
"""Return the class of this sensor."""
return self._sensor_type
2015-11-19 18:00:22 +00:00
@property
def should_poll(self):
"""No polling needed for a demo binary sensor."""
2015-11-19 18:00:22 +00:00
return False
@property
def name(self):
"""Return the name of the binary sensor."""
2015-11-19 18:00:22 +00:00
return self._name
@property
def is_on(self):
"""Return true if the binary sensor is on."""
2015-11-19 18:00:22 +00:00
return self._state