2015-08-06 16:53:44 +00:00
|
|
|
"""
|
|
|
|
Support for Wink sensors.
|
2015-10-20 19:29:19 +00:00
|
|
|
|
2015-11-09 12:12:18 +00:00
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
at https://home-assistant.io/components/sensor.wink/
|
2015-08-06 16:53:44 +00:00
|
|
|
"""
|
2015-01-20 01:16:04 +00:00
|
|
|
import logging
|
|
|
|
|
2016-02-23 19:20:54 +00:00
|
|
|
from homeassistant.const import (CONF_ACCESS_TOKEN, STATE_CLOSED,
|
2016-06-29 21:16:53 +00:00
|
|
|
STATE_OPEN, TEMP_CELSIUS)
|
2015-03-22 02:16:13 +00:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2016-06-29 21:16:53 +00:00
|
|
|
from homeassistant.components.wink import WinkDevice
|
|
|
|
from homeassistant.loader import get_component
|
2015-01-20 01:16:04 +00:00
|
|
|
|
2016-07-14 20:31:16 +00:00
|
|
|
REQUIREMENTS = ['python-wink==0.7.10', 'pubnub==3.8.2']
|
2016-02-23 19:20:54 +00:00
|
|
|
|
|
|
|
SENSOR_TYPES = ['temperature', 'humidity']
|
2015-01-20 01:16:04 +00:00
|
|
|
|
2015-12-17 03:31:34 +00:00
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Setup the Wink platform."""
|
2015-07-20 07:41:57 +00:00
|
|
|
import pywink
|
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
token = config.get(CONF_ACCESS_TOKEN)
|
2015-01-20 01:16:04 +00:00
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
if token is None:
|
|
|
|
logging.getLogger(__name__).error(
|
2015-10-21 08:47:12 +00:00
|
|
|
"Missing wink access_token. "
|
|
|
|
"Get one at https://winkbearertoken.appspot.com/")
|
2015-03-01 09:35:58 +00:00
|
|
|
return
|
2015-01-20 01:16:04 +00:00
|
|
|
|
2015-03-01 09:35:58 +00:00
|
|
|
pywink.set_bearer_token(token)
|
2015-01-20 01:16:04 +00:00
|
|
|
|
2016-02-23 19:20:54 +00:00
|
|
|
for sensor in pywink.get_sensors():
|
|
|
|
if sensor.capability() in SENSOR_TYPES:
|
|
|
|
add_devices([WinkSensorDevice(sensor)])
|
|
|
|
|
2015-12-16 18:32:38 +00:00
|
|
|
add_devices(WinkEggMinder(eggtray) for eggtray in pywink.get_eggtrays())
|
2015-03-19 06:02:58 +00:00
|
|
|
|
|
|
|
|
2016-06-29 21:16:53 +00:00
|
|
|
class WinkSensorDevice(WinkDevice, Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Wink sensor."""
|
2015-03-19 06:02:58 +00:00
|
|
|
|
|
|
|
def __init__(self, wink):
|
2016-06-29 21:16:53 +00:00
|
|
|
"""Initialize the Wink device."""
|
|
|
|
super().__init__(wink)
|
|
|
|
wink = get_component('wink')
|
2016-02-23 19:20:54 +00:00
|
|
|
self.capability = self.wink.capability()
|
|
|
|
if self.wink.UNIT == "°":
|
2016-04-20 03:30:44 +00:00
|
|
|
self._unit_of_measurement = TEMP_CELSIUS
|
2016-02-23 19:20:54 +00:00
|
|
|
else:
|
|
|
|
self._unit_of_measurement = self.wink.UNIT
|
2015-03-19 06:02:58 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state."""
|
2016-02-23 19:20:54 +00:00
|
|
|
if self.capability == "humidity":
|
2016-06-29 21:16:53 +00:00
|
|
|
return round(self.wink.humidity_percentage())
|
2016-02-23 19:20:54 +00:00
|
|
|
elif self.capability == "temperature":
|
2016-06-29 21:16:53 +00:00
|
|
|
return round(self.wink.temperature_float(), 1)
|
2016-02-23 19:20:54 +00:00
|
|
|
else:
|
|
|
|
return STATE_OPEN if self.is_open else STATE_CLOSED
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the unit of measurement of this entity, if any."""
|
2016-02-23 19:20:54 +00:00
|
|
|
return self._unit_of_measurement
|
2015-03-19 06:02:58 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_open(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return true if door is open."""
|
2015-03-19 06:02:58 +00:00
|
|
|
return self.wink.state()
|
2015-12-16 18:32:38 +00:00
|
|
|
|
2016-05-07 01:19:37 +00:00
|
|
|
|
2016-06-29 21:16:53 +00:00
|
|
|
class WinkEggMinder(WinkDevice, Entity):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Representation of a Wink Egg Minder."""
|
2015-12-16 18:32:38 +00:00
|
|
|
|
|
|
|
def __init__(self, wink):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Initialize the sensor."""
|
2016-06-29 21:16:53 +00:00
|
|
|
WinkDevice.__init__(self, wink)
|
2015-12-16 18:32:38 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
2016-03-08 15:46:34 +00:00
|
|
|
"""Return the state."""
|
2015-12-16 18:32:38 +00:00
|
|
|
return self.wink.state()
|