mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Fix optimistic mode and add tests (#22899)
This commit is contained in:
committed by
Paulus Schoutsen
parent
6463b8165f
commit
38d92b2abf
@@ -6,6 +6,7 @@ components. Instead call the service directly.
|
||||
from homeassistant.components.lock import DOMAIN
|
||||
from homeassistant.const import (
|
||||
ATTR_CODE, ATTR_ENTITY_ID, SERVICE_LOCK, SERVICE_UNLOCK, SERVICE_OPEN)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.loader import bind_hass
|
||||
|
||||
|
||||
@@ -21,6 +22,19 @@ def lock(hass, entity_id=None, code=None):
|
||||
hass.services.call(DOMAIN, SERVICE_LOCK, data)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_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.async_add_job(hass.services.async_call(DOMAIN, SERVICE_LOCK, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def unlock(hass, entity_id=None, code=None):
|
||||
"""Unlock all or specified locks."""
|
||||
@@ -33,6 +47,19 @@ def unlock(hass, entity_id=None, code=None):
|
||||
hass.services.call(DOMAIN, SERVICE_UNLOCK, data)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_unlock(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.async_add_job(hass.services.async_call(DOMAIN, SERVICE_UNLOCK, data))
|
||||
|
||||
|
||||
@bind_hass
|
||||
def open_lock(hass, entity_id=None, code=None):
|
||||
"""Open all or specified locks."""
|
||||
@@ -43,3 +70,16 @@ def open_lock(hass, entity_id=None, code=None):
|
||||
data[ATTR_ENTITY_ID] = entity_id
|
||||
|
||||
hass.services.call(DOMAIN, SERVICE_OPEN, data)
|
||||
|
||||
|
||||
@callback
|
||||
@bind_hass
|
||||
def async_open_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.async_add_job(hass.services.async_call(DOMAIN, SERVICE_OPEN, data))
|
||||
|
||||
Reference in New Issue
Block a user