2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Vera locks."""
|
2016-06-30 00:28:20 +00:00
|
|
|
import logging
|
|
|
|
|
2017-03-11 18:06:46 +00:00
|
|
|
from homeassistant.components.lock import ENTITY_ID_FORMAT, LockDevice
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
|
|
|
|
|
|
|
from . import VERA_CONTROLLER, VERA_DEVICES, VeraDevice
|
2016-06-30 00:28:20 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Find and return Vera locks."""
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(
|
2018-06-07 19:31:21 +00:00
|
|
|
[VeraLock(device, hass.data[VERA_CONTROLLER]) for
|
|
|
|
device in hass.data[VERA_DEVICES]['lock']], True)
|
2016-06-30 00:28:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
class VeraLock(VeraDevice, LockDevice):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Representation of a Vera lock."""
|
2016-06-30 00:28:20 +00:00
|
|
|
|
|
|
|
def __init__(self, vera_device, controller):
|
|
|
|
"""Initialize the Vera device."""
|
|
|
|
self._state = None
|
|
|
|
VeraDevice.__init__(self, vera_device, controller)
|
2017-03-11 18:06:46 +00:00
|
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
|
2016-06-30 00:28:20 +00:00
|
|
|
|
|
|
|
def lock(self, **kwargs):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Lock the device."""
|
2016-06-30 00:28:20 +00:00
|
|
|
self.vera_device.lock()
|
|
|
|
self._state = STATE_LOCKED
|
|
|
|
|
|
|
|
def unlock(self, **kwargs):
|
2016-06-30 08:33:34 +00:00
|
|
|
"""Unlock the device."""
|
2016-06-30 00:28:20 +00:00
|
|
|
self.vera_device.unlock()
|
|
|
|
self._state = STATE_UNLOCKED
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_locked(self):
|
|
|
|
"""Return true if device is on."""
|
|
|
|
return self._state == STATE_LOCKED
|
|
|
|
|
|
|
|
def update(self):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Update state by the Vera device callback."""
|
2016-06-30 00:28:20 +00:00
|
|
|
self._state = (STATE_LOCKED if self.vera_device.is_locked(True)
|
|
|
|
else STATE_UNLOCKED)
|