2015-11-17 15:17:57 +00:00
|
|
|
"""
|
|
|
|
Support for Wink locks.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/lock.wink/
|
|
|
|
"""
|
2015-11-19 21:54:55 +00:00
|
|
|
from homeassistant.components.lock import LockDevice
|
2017-02-02 06:43:12 +00:00
|
|
|
from homeassistant.components.wink import WinkDevice, DOMAIN
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2016-09-20 07:05:54 +00:00
|
|
|
DEPENDENCIES = ['wink']
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2015-12-17 03:45:58 +00:00
|
|
|
|
2015-11-17 15:17:57 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Wink platform."""
|
2015-11-17 15:17:57 +00:00
|
|
|
import pywink
|
|
|
|
|
2017-02-02 06:43:12 +00:00
|
|
|
for lock in pywink.get_locks():
|
2017-02-09 03:57:58 +00:00
|
|
|
_id = lock.object_id() + lock.name()
|
2017-02-02 06:43:12 +00:00
|
|
|
if _id not in hass.data[DOMAIN]['unique_ids']:
|
|
|
|
add_devices([WinkLockDevice(lock, hass)])
|
2015-11-17 15:17:57 +00:00
|
|
|
|
|
|
|
|
2016-06-29 21:16:53 +00:00
|
|
|
class WinkLockDevice(WinkDevice, LockDevice):
|
2016-03-07 21:13:18 +00:00
|
|
|
"""Representation of a Wink lock."""
|
|
|
|
|
2016-11-30 21:12:26 +00:00
|
|
|
def __init__(self, wink, hass):
|
2016-03-07 21:13:18 +00:00
|
|
|
"""Initialize the lock."""
|
2017-02-02 06:43:12 +00:00
|
|
|
super().__init__(wink, hass)
|
2015-11-17 15:17:57 +00:00
|
|
|
|
|
|
|
@property
|
2015-11-20 21:34:27 +00:00
|
|
|
def is_locked(self):
|
2016-02-28 11:03:47 +00:00
|
|
|
"""Return true if device is locked."""
|
2015-11-17 15:17:57 +00:00
|
|
|
return self.wink.state()
|
|
|
|
|
2016-02-17 10:50:36 +00:00
|
|
|
def lock(self, **kwargs):
|
2016-02-28 11:03:47 +00:00
|
|
|
"""Lock the device."""
|
2015-12-16 18:32:38 +00:00
|
|
|
self.wink.set_state(True)
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2016-02-17 10:50:36 +00:00
|
|
|
def unlock(self, **kwargs):
|
2016-02-28 11:03:47 +00:00
|
|
|
"""Unlock the device."""
|
2015-12-16 18:32:38 +00:00
|
|
|
self.wink.set_state(False)
|