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 authored and Martin Hjelmare committed 2019-04-25 10:14:16 +02:00
1 parent 86b017e2f0
commit 5376e15286
24 files changed
+498 -991

No files matched your search

+36 -61
View File
@@ -10,7 +10,6 @@ from homeassistant.components.vacuum import (
from homeassistant.const import (
ATTR_COMMAND, ATTR_ENTITY_ID, SERVICE_TOGGLE,
SERVICE_TURN_OFF, SERVICE_TURN_ON)
from homeassistant.core import callback
from homeassistant.loader import bind_hass
@@ -20,13 +19,11 @@ def turn_on(hass, entity_id=None):
hass.add_job(async_turn_on, hass, entity_id)
@callback
@bind_hass
def async_turn_on(hass, entity_id=None):
async def async_turn_on(hass, entity_id=None):
"""Turn all or specified vacuum on."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data))
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data, blocking=True)
@bind_hass
@@ -35,13 +32,11 @@ def turn_off(hass, entity_id=None):
hass.add_job(async_turn_off, hass, entity_id)
@callback
@bind_hass
def async_turn_off(hass, entity_id=None):
async def async_turn_off(hass, entity_id=None):
"""Turn all or specified vacuum off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, data))
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, data, blocking=True)
@bind_hass
@@ -50,13 +45,11 @@ def toggle(hass, entity_id=None):
hass.add_job(async_toggle, hass, entity_id)
@callback
@bind_hass
def async_toggle(hass, entity_id=None):
async def async_toggle(hass, entity_id=None):
"""Toggle all or specified vacuum."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_TOGGLE, data))
await hass.services.async_call(
DOMAIN, SERVICE_TOGGLE, data, blocking=True)
@bind_hass
@@ -65,13 +58,11 @@ def locate(hass, entity_id=None):
hass.add_job(async_locate, hass, entity_id)
@callback
@bind_hass
def async_locate(hass, entity_id=None):
async def async_locate(hass, entity_id=None):
"""Locate all or specified vacuum."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_LOCATE, data))
await hass.services.async_call(
DOMAIN, SERVICE_LOCATE, data, blocking=True)
@bind_hass
@@ -80,13 +71,11 @@ def clean_spot(hass, entity_id=None):
hass.add_job(async_clean_spot, hass, entity_id)
@callback
@bind_hass
def async_clean_spot(hass, entity_id=None):
async def async_clean_spot(hass, entity_id=None):
"""Tell all or specified vacuum to perform a spot clean-up."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_CLEAN_SPOT, data))
await hass.services.async_call(
DOMAIN, SERVICE_CLEAN_SPOT, data, blocking=True)
@bind_hass
@@ -95,13 +84,11 @@ def return_to_base(hass, entity_id=None):
hass.add_job(async_return_to_base, hass, entity_id)
@callback
@bind_hass
def async_return_to_base(hass, entity_id=None):
async def async_return_to_base(hass, entity_id=None):
"""Tell all or specified vacuum to return to base."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_RETURN_TO_BASE, data))
await hass.services.async_call(
DOMAIN, SERVICE_RETURN_TO_BASE, data, blocking=True)
@bind_hass
@@ -110,13 +97,11 @@ def start_pause(hass, entity_id=None):
hass.add_job(async_start_pause, hass, entity_id)
@callback
@bind_hass
def async_start_pause(hass, entity_id=None):
async def async_start_pause(hass, entity_id=None):
"""Tell all or specified vacuum to start or pause the current task."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_START_PAUSE, data))
await hass.services.async_call(
DOMAIN, SERVICE_START_PAUSE, data, blocking=True)
@bind_hass
@@ -125,13 +110,11 @@ def start(hass, entity_id=None):
hass.add_job(async_start, hass, entity_id)
@callback
@bind_hass
def async_start(hass, entity_id=None):
async def async_start(hass, entity_id=None):
"""Tell all or specified vacuum to start or resume the current task."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_START, data))
await hass.services.async_call(
DOMAIN, SERVICE_START, data, blocking=True)
@bind_hass
@@ -140,13 +123,11 @@ def pause(hass, entity_id=None):
hass.add_job(async_pause, hass, entity_id)
@callback
@bind_hass
def async_pause(hass, entity_id=None):
async def async_pause(hass, entity_id=None):
"""Tell all or the specified vacuum to pause the current task."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_PAUSE, data))
await hass.services.async_call(
DOMAIN, SERVICE_PAUSE, data, blocking=True)
@bind_hass
@@ -155,13 +136,11 @@ def stop(hass, entity_id=None):
hass.add_job(async_stop, hass, entity_id)
@callback
@bind_hass
def async_stop(hass, entity_id=None):
async def async_stop(hass, entity_id=None):
"""Stop all or specified vacuum."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else None
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_STOP, data))
await hass.services.async_call(
DOMAIN, SERVICE_STOP, data, blocking=True)
@bind_hass
@@ -170,14 +149,12 @@ def set_fan_speed(hass, fan_speed, entity_id=None):
hass.add_job(async_set_fan_speed, hass, fan_speed, entity_id)
@callback
@bind_hass
def async_set_fan_speed(hass, fan_speed, entity_id=None):
async def async_set_fan_speed(hass, fan_speed, entity_id=None):
"""Set fan speed for all or specified vacuum."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
data[ATTR_FAN_SPEED] = fan_speed
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_SET_FAN_SPEED, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_FAN_SPEED, data, blocking=True)
@bind_hass
@@ -186,13 +163,11 @@ def send_command(hass, command, params=None, entity_id=None):
hass.add_job(async_send_command, hass, command, params, entity_id)
@callback
@bind_hass
def async_send_command(hass, command, params=None, entity_id=None):
async def async_send_command(hass, command, params=None, entity_id=None):
"""Send command to all or specified vacuum."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
data[ATTR_COMMAND] = command
if params is not None:
data[ATTR_PARAMS] = params
hass.async_add_job(hass.services.async_call(
DOMAIN, SERVICE_SEND_COMMAND, data))
await hass.services.async_call(
DOMAIN, SERVICE_SEND_COMMAND, data, blocking=True)