2015-11-17 15:17:57 +00:00
|
|
|
"""
|
2016-02-24 09:38:06 +00:00
|
|
|
Demo lock platform that has two fake locks.
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2016-02-24 09:38:06 +00:00
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/demo/
|
2015-11-17 15:17:57 +00:00
|
|
|
"""
|
|
|
|
from homeassistant.components.lock import LockDevice
|
2016-08-22 12:20:04 +00:00
|
|
|
from homeassistant.const import (STATE_LOCKED, STATE_UNLOCKED)
|
2015-11-17 15:17:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=unused-argument
|
2016-08-22 12:20:04 +00:00
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
2017-05-02 16:18:47 +00:00
|
|
|
"""Set up the Demo lock platform."""
|
2016-08-22 12:20:04 +00:00
|
|
|
add_devices([
|
2015-11-29 19:44:27 +00:00
|
|
|
DemoLock('Front Door', STATE_LOCKED),
|
|
|
|
DemoLock('Kitchen Door', STATE_UNLOCKED)
|
2015-11-17 15:17:57 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
class DemoLock(LockDevice):
|
2016-08-22 12:20:04 +00:00
|
|
|
"""Representation of a Demo lock."""
|
2016-03-07 21:13:18 +00:00
|
|
|
|
2015-11-29 19:44:27 +00:00
|
|
|
def __init__(self, name, state):
|
2016-03-07 21:13:18 +00:00
|
|
|
"""Initialize the lock."""
|
2015-11-29 19:44:27 +00:00
|
|
|
self._name = name
|
2015-11-17 15:17:57 +00:00
|
|
|
self._state = state
|
|
|
|
|
|
|
|
@property
|
|
|
|
def should_poll(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""No polling needed for a demo lock."""
|
2015-11-17 15:17:57 +00:00
|
|
|
return False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return the name of the lock if any."""
|
2015-11-17 15:17:57 +00:00
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
2015-11-20 21:34:27 +00:00
|
|
|
def is_locked(self):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Return true if lock is locked."""
|
2015-11-29 19:44:27 +00:00
|
|
|
return self._state == STATE_LOCKED
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2015-11-19 21:54:55 +00:00
|
|
|
def lock(self, **kwargs):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Lock the device."""
|
2015-11-17 15:17:57 +00:00
|
|
|
self._state = STATE_LOCKED
|
2017-02-06 20:25:34 +00:00
|
|
|
self.schedule_update_ha_state()
|
2015-11-17 15:17:57 +00:00
|
|
|
|
2015-11-19 21:54:55 +00:00
|
|
|
def unlock(self, **kwargs):
|
2016-02-24 09:38:06 +00:00
|
|
|
"""Unlock the device."""
|
2015-11-17 15:17:57 +00:00
|
|
|
self._state = STATE_UNLOCKED
|
2017-02-06 20:25:34 +00:00
|
|
|
self.schedule_update_ha_state()
|