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

+18 -28
View File
@@ -8,13 +8,10 @@ from homeassistant.components.fan import (
SERVICE_OSCILLATE, SERVICE_SET_DIRECTION, SERVICE_SET_SPEED)
from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
from homeassistant.loader import bind_hass
from homeassistant.core import callback
@callback
@bind_hass
def async_turn_on(hass, entity_id: str = None, speed: str = None) -> None:
async def async_turn_on(hass, entity_id: str = None,
speed: str = None) -> None:
"""Turn all or specified fan on."""
data = {
key: value for key, value in [
@@ -23,24 +20,20 @@ def async_turn_on(hass, entity_id: str = None, speed: str = None) -> None:
] if value is not None
}
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_TURN_ON, data))
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, data, blocking=True)
@callback
@bind_hass
def async_turn_off(hass, entity_id: str = None) -> None:
async def async_turn_off(hass, entity_id: str = None) -> None:
"""Turn all or specified fan off."""
data = {ATTR_ENTITY_ID: entity_id} if entity_id else {}
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF, data))
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, data, blocking=True)
@callback
@bind_hass
def async_oscillate(hass, entity_id: str = None,
should_oscillate: bool = True) -> None:
async def async_oscillate(hass, entity_id: str = None,
should_oscillate: bool = True) -> None:
"""Set oscillation on all or specified fan."""
data = {
key: value for key, value in [
@@ -49,13 +42,12 @@ def async_oscillate(hass, entity_id: str = None,
] if value is not None
}
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_OSCILLATE, data))
await hass.services.async_call(
DOMAIN, SERVICE_OSCILLATE, data, blocking=True)
@callback
@bind_hass
def async_set_speed(hass, entity_id: str = None, speed: str = None) -> None:
async def async_set_speed(hass, entity_id: str = None,
speed: str = None) -> None:
"""Set speed for all or specified fan."""
data = {
key: value for key, value in [
@@ -64,13 +56,11 @@ def async_set_speed(hass, entity_id: str = None, speed: str = None) -> None:
] if value is not None
}
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_SPEED, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_SPEED, data, blocking=True)
@callback
@bind_hass
def async_set_direction(
async def async_set_direction(
hass, entity_id: str = None, direction: str = None) -> None:
"""Set direction for all or specified fan."""
data = {
@@ -80,5 +70,5 @@ def async_set_direction(
] if value is not None
}
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_DIRECTION, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_DIRECTION, data, blocking=True)