Convert some test helpers to coroutines and adjust tests (#23352)

* Convert some test helpers to coroutines

* Fix tests
This commit is contained in:
Erik Montnemery 2019-04-25 10:14:16 +02:00 committed by Martin Hjelmare
parent 86b017e2f0
commit 5376e15286
24 changed files with 498 additions and 991 deletions

View file

@ -6,7 +6,6 @@ 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
@ -22,9 +21,7 @@ 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):
async def async_lock(hass, entity_id=None, code=None):
"""Lock all or specified locks."""
data = {}
if code:
@ -32,7 +29,7 @@ def async_lock(hass, entity_id=None, code=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_LOCK, data))
await hass.services.async_call(DOMAIN, SERVICE_LOCK, data, blocking=True)
@bind_hass
@ -47,9 +44,7 @@ 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):
async def async_unlock(hass, entity_id=None, code=None):
"""Lock all or specified locks."""
data = {}
if code:
@ -57,7 +52,7 @@ def async_unlock(hass, entity_id=None, code=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_UNLOCK, data))
await hass.services.async_call(DOMAIN, SERVICE_UNLOCK, data, blocking=True)
@bind_hass
@ -72,9 +67,7 @@ def open_lock(hass, entity_id=None, code=None):
hass.services.call(DOMAIN, SERVICE_OPEN, data)
@callback
@bind_hass
def async_open_lock(hass, entity_id=None, code=None):
async def async_open_lock(hass, entity_id=None, code=None):
"""Lock all or specified locks."""
data = {}
if code:
@ -82,4 +75,4 @@ def async_open_lock(hass, entity_id=None, code=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_OPEN, data))
await hass.services.async_call(DOMAIN, SERVICE_OPEN, data, blocking=True)