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-11-06 15:27:15 +00:00
|
|
|
from homeassistant.const import 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-09-20 07:05:54 +00:00
|
|
|
DEPENDENCIES = ['wink']
|
2016-02-23 19:20:54 +00:00
|
|
|
|
2016-10-02 03:45:39 +00:00
|
|
|
SENSOR_TYPES = ['temperature', 'humidity', 'balance', 'proximity']
|
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-10-30 08:58:34 +00:00
|
|
|
"""Set up the Wink platform."""
|
2015-07-20 07:41:57 +00:00
|
|
|
import pywink
|
|
|
|
|
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-09-20 07:05:54 +00:00
|
|
|
for piggy_bank in pywink.get_piggy_banks():
|
|
|
|
try:
|
|
|
|
if piggy_bank.capability() in SENSOR_TYPES:
|
|
|
|
add_devices([WinkSensorDevice(piggy_bank)])
|
|
|
|
except AttributeError:
|
2016-10-30 08:58:34 +00:00
|
|
|
logging.getLogger(__name__).error("Device is not a sensor")
|
2016-09-20 07:05:54 +00:00
|
|
|
|
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()
|
2016-10-30 08:58:34 +00:00
|
|
|
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-11-06 15:27:15 +00:00
|
|
|
state = None
|
2016-10-30 08:58:34 +00:00
|
|
|
if self.capability == 'humidity':
|
2016-11-06 15:27:15 +00:00
|
|
|
if self.wink.humidity_percentage() is not None:
|
|
|
|
state = round(self.wink.humidity_percentage())
|
2016-10-30 08:58:34 +00:00
|
|
|
elif self.capability == 'temperature':
|
2016-11-06 15:27:15 +00:00
|
|
|
if self.wink.temperature_float() is not None:
|
|
|
|
state = round(self.wink.temperature_float(), 1)
|
2016-10-30 08:58:34 +00:00
|
|
|
elif self.capability == 'balance':
|
2016-11-06 15:27:15 +00:00
|
|
|
if self.wink.balance() is not None:
|
|
|
|
state = round(self.wink.balance() / 100, 2)
|
2016-10-30 08:58:34 +00:00
|
|
|
elif self.capability == 'proximity':
|
2016-11-06 15:27:15 +00:00
|
|
|
if self.wink.proximity_float() is not None:
|
|
|
|
state = self.wink.proximity_float()
|
2016-02-23 19:20:54 +00:00
|
|
|
else:
|
2016-11-06 15:27:15 +00:00
|
|
|
# A sensor should never get here, anything that does
|
|
|
|
# will require an update to python-wink
|
|
|
|
logging.getLogger(__name__).error("Please report this as an issue")
|
|
|
|
state = None
|
|
|
|
return state
|
2016-02-23 19:20:54 +00:00
|
|
|
|
2016-09-20 07:05:54 +00:00
|
|
|
@property
|
|
|
|
def available(self):
|
2016-11-06 15:27:15 +00:00
|
|
|
"""True if connection == True."""
|
2016-09-20 07:05:54 +00:00
|
|
|
return self.wink.available
|
|
|
|
|
2016-02-23 19:20:54 +00:00
|
|
|
@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
|
|
|
|
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()
|