2015-05-10 21:43:37 +00:00
|
|
|
"""
|
2015-09-07 17:40:09 +00:00
|
|
|
Demo platform that has a couple of fake sensors.
|
2016-02-24 09:38:06 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/demo/
|
2015-05-10 21:43:37 +00:00
|
|
|
"""
|
2018-05-05 13:37:40 +00:00
|
|
|
from homeassistant.const import (
|
|
|
|
ATTR_BATTERY_LEVEL, TEMP_CELSIUS, DEVICE_CLASS_HUMIDITY,
|
|
|
|
DEVICE_CLASS_TEMPERATURE)
|
2015-03-22 02:16:13 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Demo sensors."""
|
2015-03-01 09:35:58 +00:00
|
|
|
add_devices([
|
2018-05-05 13:37:40 +00:00
|
|
|
DemoSensor('Outside Temperature', 15.6, DEVICE_CLASS_TEMPERATURE,
|
2018-05-03 17:51:36 +00:00
|
|
|
TEMP_CELSIUS, 12),
|
2018-05-05 13:37:40 +00:00
|
|
|
DemoSensor('Outside Humidity', 54, DEVICE_CLASS_HUMIDITY, '%', None),
|
2015-03-01 09:35:58 +00:00
|
|
|
])
|
2015-02-28 15:31:39 +00:00
|
|
|
|
|
|
|
|
2015-03-22 02:16:13 +00:00
|
|
|
class DemoSensor(Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Demo sensor."""
|
|
|
|
|
2018-05-03 17:51:36 +00:00
|
|
|
def __init__(self, name, state, device_class,
|
|
|
|
unit_of_measurement, battery):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2015-02-28 15:31:39 +00:00
|
|
|
self._name = name
|
|
|
|
self._state = state
|
2018-05-03 17:51:36 +00:00
|
|
|
self._device_class = device_class
|
2015-02-28 15:31:39 +00:00
|
|
|
self._unit_of_measurement = unit_of_measurement
|
2015-03-19 06:02:58 +00:00
|
|
|
self._battery = battery
|
2015-02-28 15:31:39 +00:00
|
|
|
|
2015-03-17 05:20:31 +00:00
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2016-02-23 05:21:49 +00:00
|
|
|
"""No polling needed for a demo sensor."""
|
2015-03-17 05:20:31 +00:00
|
|
|
return False
|
|
|
|
|
2018-05-03 17:51:36 +00:00
|
|
|
@property
|
|
|
|
def device_class(self):
|
|
|
|
"""Return the device class of the sensor."""
|
|
|
|
return self._device_class
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
@property
|
|
|
|
def name(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the name of the sensor."""
|
2015-02-28 15:31:39 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the state of the sensor."""
|
2015-02-28 15:31:39 +00:00
|
|
|
return self._state
|
|
|
|
|
2015-03-19 06:02:58 +00:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the unit this state is expressed in."""
|
2015-03-19 06:02:58 +00:00
|
|
|
return self._unit_of_measurement
|
|
|
|
|
2015-02-28 15:31:39 +00:00
|
|
|
@property
|
2016-02-07 06:28:29 +00:00
|
|
|
def device_state_attributes(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the state attributes."""
|
2015-03-19 06:02:58 +00:00
|
|
|
if self._battery:
|
|
|
|
return {
|
|
|
|
ATTR_BATTERY_LEVEL: self._battery,
|
|
|
|
}
|