2018-09-26 16:02:05 +00:00
|
|
|
"""Collection of helper methods.
|
|
|
|
|
|
|
|
All containing methods are legacy helpers that should not be used by new
|
|
|
|
components. Instead call the service directly.
|
|
|
|
"""
|
|
|
|
from homeassistant.components.lock import DOMAIN
|
|
|
|
from homeassistant.const import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_CODE,
|
|
|
|
ATTR_ENTITY_ID,
|
|
|
|
SERVICE_LOCK,
|
|
|
|
SERVICE_UNLOCK,
|
|
|
|
SERVICE_OPEN,
|
|
|
|
)
|
2018-09-26 16:02:05 +00:00
|
|
|
from homeassistant.loader import bind_hass
|
|
|
|
|
|
|
|
|
|
|
|
@bind_hass
|
|
|
|
def lock(hass, entity_id=None, code=None):
|
|
|
|
"""Lock all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
|
|
|
hass.services.call(DOMAIN, SERVICE_LOCK, data)
|
|
|
|
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
async def async_lock(hass, entity_id=None, code=None):
|
2019-04-10 20:56:34 +00:00
|
|
|
"""Lock all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_LOCK, data, blocking=True)
|
2019-04-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
2018-09-26 16:02:05 +00:00
|
|
|
@bind_hass
|
|
|
|
def unlock(hass, entity_id=None, code=None):
|
|
|
|
"""Unlock all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
|
|
|
hass.services.call(DOMAIN, SERVICE_UNLOCK, data)
|
|
|
|
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
async def async_unlock(hass, entity_id=None, code=None):
|
2019-04-10 20:56:34 +00:00
|
|
|
"""Lock all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_UNLOCK, data, blocking=True)
|
2019-04-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
2018-09-26 16:02:05 +00:00
|
|
|
@bind_hass
|
|
|
|
def open_lock(hass, entity_id=None, code=None):
|
|
|
|
"""Open all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
|
|
|
hass.services.call(DOMAIN, SERVICE_OPEN, data)
|
2019-04-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
async def async_open_lock(hass, entity_id=None, code=None):
|
2019-04-10 20:56:34 +00:00
|
|
|
"""Lock all or specified locks."""
|
|
|
|
data = {}
|
|
|
|
if code:
|
|
|
|
data[ATTR_CODE] = code
|
|
|
|
if entity_id:
|
|
|
|
data[ATTR_ENTITY_ID] = entity_id
|
|
|
|
|
2019-04-25 08:14:16 +00:00
|
|
|
await hass.services.async_call(DOMAIN, SERVICE_OPEN, data, blocking=True)
|