2016-02-01 02:39:04 +00:00
|
|
|
"""
|
|
|
|
Support for Wink garage doors.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/garage_door.wink/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.garage_door import GarageDoorDevice
|
2016-06-29 21:16:53 +00:00
|
|
|
from homeassistant.components.wink import WinkDevice
|
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
2016-02-01 02:39:04 +00:00
|
|
|
|
2016-09-11 14:30:31 +00:00
|
|
|
REQUIREMENTS = ['python-wink==0.7.14', 'pubnub==3.8.2']
|
2016-02-01 02:39:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2016-03-07 20:22:21 +00:00
|
|
|
"""Setup the Wink garage door platform."""
|
2016-02-01 02:39:04 +00:00
|
|
|
import pywink
|
|
|
|
|
|
|
|
if discovery_info is None:
|
|
|
|
token = config.get(CONF_ACCESS_TOKEN)
|
|
|
|
|
|
|
|
if token is None:
|
|
|
|
logging.getLogger(__name__).error(
|
|
|
|
"Missing wink access_token. "
|
|
|
|
"Get one at https://winkbearertoken.appspot.com/")
|
|
|
|
return
|
|
|
|
|
|
|
|
pywink.set_bearer_token(token)
|
|
|
|
|
|
|
|
add_devices(WinkGarageDoorDevice(door) for door in
|
|
|
|
pywink.get_garage_doors())
|
|
|
|
|
|
|
|
|
2016-06-29 21:16:53 +00:00
|
|
|
class WinkGarageDoorDevice(WinkDevice, GarageDoorDevice):
|
2016-03-07 20:22:21 +00:00
|
|
|
"""Representation of a Wink garage door."""
|
2016-02-01 02:39:04 +00:00
|
|
|
|
|
|
|
def __init__(self, wink):
|
2016-03-07 20:22:21 +00:00
|
|
|
"""Initialize the garage door."""
|
2016-06-29 21:16:53 +00:00
|
|
|
WinkDevice.__init__(self, wink)
|
2016-02-01 02:39:04 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
2016-03-07 20:22:21 +00:00
|
|
|
"""Return true if door is closed."""
|
2016-02-01 02:39:04 +00:00
|
|
|
return self.wink.state() == 0
|
|
|
|
|
2016-02-05 20:10:53 +00:00
|
|
|
def close_door(self):
|
2016-03-07 20:22:21 +00:00
|
|
|
"""Close the door."""
|
2016-02-01 02:39:04 +00:00
|
|
|
self.wink.set_state(0)
|
|
|
|
|
2016-02-05 20:10:53 +00:00
|
|
|
def open_door(self):
|
2016-02-24 09:07:54 +00:00
|
|
|
"""Open the door."""
|
2016-02-01 02:39:04 +00:00
|
|
|
self.wink.set_state(1)
|