2019-04-03 17:40:03 +02:00
|
|
|
"""Demo lock platform that has two fake locks."""
|
2020-04-25 18:02:41 +02:00
|
|
|
from homeassistant.components.lock import SUPPORT_OPEN, LockEntity
|
2019-12-08 17:59:27 +01:00
|
|
|
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED
|
2015-11-17 10:17:57 -05:00
|
|
|
|
|
|
|
|
2019-11-13 16:37:31 +01:00
|
|
|
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
2017-05-02 18:18:47 +02:00
|
|
|
"""Set up the Demo lock platform."""
|
2019-11-13 16:37:31 +01:00
|
|
|
async_add_entities(
|
2019-07-31 12:25:30 -07:00
|
|
|
[
|
|
|
|
DemoLock("Front Door", STATE_LOCKED),
|
|
|
|
DemoLock("Kitchen Door", STATE_UNLOCKED),
|
|
|
|
DemoLock("Openable Lock", STATE_LOCKED, True),
|
|
|
|
]
|
|
|
|
)
|
2015-11-17 10:17:57 -05:00
|
|
|
|
|
|
|
|
2019-11-13 16:37:31 +01:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Demo config entry."""
|
|
|
|
await async_setup_platform(hass, {}, async_add_entities)
|
|
|
|
|
|
|
|
|
2020-04-25 18:02:41 +02:00
|
|
|
class DemoLock(LockEntity):
|
2016-08-22 14:20:04 +02:00
|
|
|
"""Representation of a Demo lock."""
|
2016-03-07 22:13:18 +01:00
|
|
|
|
2021-06-17 11:25:33 +02:00
|
|
|
_attr_should_poll = False
|
2015-11-17 10:17:57 -05:00
|
|
|
|
2021-06-17 11:25:33 +02:00
|
|
|
def __init__(self, name: str, state: str, openable: bool = False) -> None:
|
|
|
|
"""Initialize the lock."""
|
|
|
|
self._attr_name = name
|
|
|
|
self._attr_is_locked = state == STATE_LOCKED
|
|
|
|
if openable:
|
|
|
|
self._attr_supported_features = SUPPORT_OPEN
|
2015-11-17 10:17:57 -05:00
|
|
|
|
2015-11-19 16:54:55 -05:00
|
|
|
def lock(self, **kwargs):
|
2016-02-24 10:38:06 +01:00
|
|
|
"""Lock the device."""
|
2021-06-17 11:25:33 +02:00
|
|
|
self._attr_is_locked = True
|
2017-02-06 21:25:34 +01:00
|
|
|
self.schedule_update_ha_state()
|
2015-11-17 10:17:57 -05:00
|
|
|
|
2015-11-19 16:54:55 -05:00
|
|
|
def unlock(self, **kwargs):
|
2016-02-24 10:38:06 +01:00
|
|
|
"""Unlock the device."""
|
2021-06-17 11:25:33 +02:00
|
|
|
self._attr_is_locked = False
|
2017-02-06 21:25:34 +01:00
|
|
|
self.schedule_update_ha_state()
|
2018-03-25 23:25:28 +02:00
|
|
|
|
|
|
|
def open(self, **kwargs):
|
|
|
|
"""Open the door latch."""
|
2021-06-17 11:25:33 +02:00
|
|
|
self._attr_is_locked = False
|
2018-03-25 23:25:28 +02:00
|
|
|
self.schedule_update_ha_state()
|