2016-02-23 14:20:54 -05:00
|
|
|
"""
|
2016-09-20 03:05:54 -04:00
|
|
|
Support for Wink binary sensors.
|
2016-02-23 14:20:54 -05:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
2016-09-20 03:05:54 -04:00
|
|
|
at https://home-assistant.io/components/binary_sensor.wink/
|
2016-02-23 14:20:54 -05:00
|
|
|
"""
|
|
|
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorDevice
|
2016-06-29 17:16:53 -04:00
|
|
|
from homeassistant.components.sensor.wink import WinkDevice
|
2016-02-23 14:20:54 -05:00
|
|
|
from homeassistant.helpers.entity import Entity
|
2016-06-29 17:16:53 -04:00
|
|
|
from homeassistant.loader import get_component
|
2016-02-23 14:20:54 -05:00
|
|
|
|
2016-09-20 03:05:54 -04:00
|
|
|
DEPENDENCIES = ['wink']
|
2016-02-23 14:20:54 -05:00
|
|
|
|
|
|
|
# These are the available sensors mapped to binary_sensor class
|
|
|
|
SENSOR_TYPES = {
|
|
|
|
"opened": "opening",
|
|
|
|
"brightness": "light",
|
|
|
|
"vibration": "vibration",
|
2016-07-20 10:39:45 -04:00
|
|
|
"loudness": "sound",
|
2016-09-20 03:05:54 -04:00
|
|
|
"liquid_detected": "moisture",
|
2016-10-01 23:45:39 -04:00
|
|
|
"motion": "motion",
|
2016-10-04 04:07:50 -04:00
|
|
|
"presence": "occupancy",
|
|
|
|
"co_detected": "gas",
|
|
|
|
"smoke_detected": "smoke"
|
2016-02-23 14:20:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-07-13 14:47:29 +02:00
|
|
|
"""Setup the Wink binary sensor platform."""
|
2016-02-23 14:20:54 -05:00
|
|
|
import pywink
|
|
|
|
|
|
|
|
for sensor in pywink.get_sensors():
|
|
|
|
if sensor.capability() in SENSOR_TYPES:
|
2016-11-30 16:12:26 -05:00
|
|
|
add_devices([WinkBinarySensorDevice(sensor, hass)])
|
2016-02-23 14:20:54 -05:00
|
|
|
|
2016-07-14 16:31:16 -04:00
|
|
|
for key in pywink.get_keys():
|
2016-11-30 16:12:26 -05:00
|
|
|
add_devices([WinkBinarySensorDevice(key, hass)])
|
2016-07-14 16:31:16 -04:00
|
|
|
|
2016-10-04 04:07:50 -04:00
|
|
|
for sensor in pywink.get_smoke_and_co_detectors():
|
2016-11-30 16:12:26 -05:00
|
|
|
add_devices([WinkBinarySensorDevice(sensor, hass)])
|
2016-10-04 04:07:50 -04:00
|
|
|
|
2016-02-23 14:20:54 -05:00
|
|
|
|
2016-06-29 17:16:53 -04:00
|
|
|
class WinkBinarySensorDevice(WinkDevice, BinarySensorDevice, Entity):
|
2016-07-13 14:47:29 +02:00
|
|
|
"""Representation of a Wink binary sensor."""
|
2016-02-23 14:20:54 -05:00
|
|
|
|
2016-11-30 16:12:26 -05:00
|
|
|
def __init__(self, wink, hass):
|
2016-03-07 20:21:08 +01:00
|
|
|
"""Initialize the Wink binary sensor."""
|
2016-11-30 16:12:26 -05:00
|
|
|
super().__init__(wink, hass)
|
2016-06-29 17:16:53 -04:00
|
|
|
wink = get_component('wink')
|
2016-02-23 14:20:54 -05:00
|
|
|
self._unit_of_measurement = self.wink.UNIT
|
|
|
|
self.capability = self.wink.capability()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_on(self):
|
2016-03-07 20:21:08 +01:00
|
|
|
"""Return true if the binary sensor is on."""
|
2016-02-23 14:20:54 -05:00
|
|
|
if self.capability == "loudness":
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.loudness_boolean()
|
2016-02-23 14:20:54 -05:00
|
|
|
elif self.capability == "vibration":
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.vibration_boolean()
|
2016-02-23 14:20:54 -05:00
|
|
|
elif self.capability == "brightness":
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.brightness_boolean()
|
2016-07-20 10:39:45 -04:00
|
|
|
elif self.capability == "liquid_detected":
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.liquid_boolean()
|
2016-09-20 03:05:54 -04:00
|
|
|
elif self.capability == "motion":
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.motion_boolean()
|
|
|
|
elif self.capability == "presence":
|
|
|
|
state = self.wink.presence_boolean()
|
2016-10-04 04:07:50 -04:00
|
|
|
elif self.capability == "co_detected":
|
|
|
|
state = self.wink.co_detected_boolean()
|
|
|
|
elif self.capability == "smoke_detected":
|
|
|
|
state = self.wink.smoke_detected_boolean()
|
2016-02-23 14:20:54 -05:00
|
|
|
else:
|
2016-10-01 23:45:39 -04:00
|
|
|
state = self.wink.state()
|
|
|
|
|
|
|
|
return state
|
2016-02-23 14:20:54 -05:00
|
|
|
|
|
|
|
@property
|
|
|
|
def sensor_class(self):
|
|
|
|
"""Return the class of this sensor, from SENSOR_CLASSES."""
|
|
|
|
return SENSOR_TYPES.get(self.capability)
|