2015-02-28 07:31:39 -08:00
|
|
|
""" Support for Wink sensors. """
|
2015-03-05 23:18:22 -08:00
|
|
|
from homeassistant.helpers.device import Device
|
2015-03-18 23:02:58 -07:00
|
|
|
from homeassistant.const import TEMP_CELCIUS, ATTR_BATTERY_LEVEL
|
2015-02-28 07:31:39 -08:00
|
|
|
|
|
|
|
|
2015-03-01 01:35:58 -08:00
|
|
|
# pylint: disable=unused-argument
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
""" Sets up the Demo sensors. """
|
|
|
|
add_devices([
|
2015-03-18 23:02:58 -07:00
|
|
|
DemoSensor('Outside Temperature', 15.6, TEMP_CELCIUS, 12),
|
|
|
|
DemoSensor('Outside Humidity', 54, '%', None),
|
2015-03-01 01:35:58 -08:00
|
|
|
])
|
2015-02-28 07:31:39 -08:00
|
|
|
|
|
|
|
|
|
|
|
class DemoSensor(Device):
|
|
|
|
""" A Demo sensor. """
|
|
|
|
|
2015-03-18 23:02:58 -07:00
|
|
|
def __init__(self, name, state, unit_of_measurement, battery):
|
2015-02-28 07:31:39 -08:00
|
|
|
self._name = name
|
|
|
|
self._state = state
|
|
|
|
self._unit_of_measurement = unit_of_measurement
|
2015-03-18 23:02:58 -07:00
|
|
|
self._battery = battery
|
2015-02-28 07:31:39 -08:00
|
|
|
|
2015-03-16 22:20:31 -07:00
|
|
|
@property
|
|
|
|
def should_poll(self):
|
|
|
|
""" No polling needed for a demo sensor. """
|
|
|
|
return False
|
|
|
|
|
2015-02-28 07:31:39 -08:00
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the device. """
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
""" Returns the state of the device. """
|
|
|
|
return self._state
|
|
|
|
|
2015-03-18 23:02:58 -07:00
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
""" Unit this state is expressed in. """
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
2015-02-28 07:31:39 -08:00
|
|
|
@property
|
|
|
|
def state_attributes(self):
|
|
|
|
""" Returns the state attributes. """
|
2015-03-18 23:02:58 -07:00
|
|
|
if self._battery:
|
|
|
|
return {
|
|
|
|
ATTR_BATTERY_LEVEL: self._battery,
|
|
|
|
}
|