core/homeassistant/components/lock/demo.py

52 lines
1.3 KiB
Python
Raw Normal View History

"""
Demo lock platform that has two fake locks.
For more details about this platform, please refer to the documentation
https://home-assistant.io/components/demo/
"""
from homeassistant.components.lock import LockDevice
2015-11-29 19:44:27 +00:00
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices_callback, discovery_info=None):
2016-03-07 21:13:18 +00:00
"""Setup the demo lock platform."""
add_devices_callback([
2015-11-29 19:44:27 +00:00
DemoLock('Front Door', STATE_LOCKED),
DemoLock('Kitchen Door', STATE_UNLOCKED)
])
class DemoLock(LockDevice):
2016-03-07 21:13:18 +00:00
"""Representation of a demo lock."""
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
self._state = state
@property
def should_poll(self):
"""No polling needed for a demo lock."""
return False
@property
def name(self):
"""Return the name of the lock if any."""
return self._name
@property
def is_locked(self):
"""Return true if lock is locked."""
2015-11-29 19:44:27 +00:00
return self._state == STATE_LOCKED
def lock(self, **kwargs):
"""Lock the device."""
self._state = STATE_LOCKED
self.update_ha_state()
def unlock(self, **kwargs):
"""Unlock the device."""
self._state = STATE_UNLOCKED
self.update_ha_state()