2016-02-01 02:39:04 +00:00
|
|
|
"""
|
|
|
|
homeassistant.components.garage_door.wink
|
2016-02-12 07:21:39 +00:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
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
|
|
|
|
from homeassistant.const import CONF_ACCESS_TOKEN
|
|
|
|
|
2016-02-21 17:01:32 +00:00
|
|
|
REQUIREMENTS = ['python-wink==0.6.1']
|
2016-02-01 02:39:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
""" Sets up the Wink platform. """
|
|
|
|
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())
|
|
|
|
|
|
|
|
|
|
|
|
class WinkGarageDoorDevice(GarageDoorDevice):
|
|
|
|
""" Represents a Wink garage door. """
|
|
|
|
|
|
|
|
def __init__(self, wink):
|
|
|
|
self.wink = wink
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unique_id(self):
|
|
|
|
""" Returns the id of this wink garage door """
|
|
|
|
return "{}.{}".format(self.__class__, self.wink.device_id())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
""" Returns the name of the garage door if any. """
|
|
|
|
return self.wink.name()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
""" Update the state of the garage door. """
|
|
|
|
self.wink.update_state()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
""" True if device is closed. """
|
|
|
|
return self.wink.state() == 0
|
|
|
|
|
2016-02-05 20:10:53 +00:00
|
|
|
def close_door(self):
|
2016-02-01 02:39:04 +00:00
|
|
|
""" Close the device. """
|
|
|
|
self.wink.set_state(0)
|
|
|
|
|
2016-02-05 20:10:53 +00:00
|
|
|
def open_door(self):
|
2016-02-01 02:39:04 +00:00
|
|
|
""" Open the device. """
|
|
|
|
self.wink.set_state(1)
|