1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

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

@@ -12,13 +12,10 @@ from homeassistant.components.climate.const import (
SERVICE_SET_FAN_MODE, SERVICE_SET_OPERATION_MODE, SERVICE_SET_SWING_MODE)
from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_TEMPERATURE)
from homeassistant.core import callback
from homeassistant.loader import bind_hass
@callback
@bind_hass
def async_set_away_mode(hass, away_mode, entity_id=None):
async def async_set_away_mode(hass, away_mode, entity_id=None):
"""Turn all or specified climate devices away mode on."""
data = {
ATTR_AWAY_MODE: away_mode
@@ -27,8 +24,8 @@ def async_set_away_mode(hass, away_mode, entity_id=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_AWAY_MODE, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_AWAY_MODE, data, blocking=True)
@bind_hass
@@ -44,9 +41,7 @@ def set_away_mode(hass, away_mode, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_AWAY_MODE, data)
@callback
@bind_hass
def async_set_hold_mode(hass, hold_mode, entity_id=None):
async def async_set_hold_mode(hass, hold_mode, entity_id=None):
"""Set new hold mode."""
data = {
ATTR_HOLD_MODE: hold_mode
@@ -55,8 +50,8 @@ def async_set_hold_mode(hass, hold_mode, entity_id=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_HOLD_MODE, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_HOLD_MODE, data, blocking=True)
@bind_hass
@@ -72,9 +67,7 @@ def set_hold_mode(hass, hold_mode, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_HOLD_MODE, data)
@callback
@bind_hass
def async_set_aux_heat(hass, aux_heat, entity_id=None):
async def async_set_aux_heat(hass, aux_heat, entity_id=None):
"""Turn all or specified climate devices auxiliary heater on."""
data = {
ATTR_AUX_HEAT: aux_heat
@@ -83,8 +76,8 @@ def async_set_aux_heat(hass, aux_heat, entity_id=None):
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_AUX_HEAT, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_AUX_HEAT, data, blocking=True)
@bind_hass
@@ -100,11 +93,9 @@ def set_aux_heat(hass, aux_heat, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_AUX_HEAT, data)
@callback
@bind_hass
def async_set_temperature(hass, temperature=None, entity_id=None,
target_temp_high=None, target_temp_low=None,
operation_mode=None):
async def async_set_temperature(hass, temperature=None, entity_id=None,
target_temp_high=None, target_temp_low=None,
operation_mode=None):
"""Set new target temperature."""
kwargs = {
key: value for key, value in [
@@ -116,8 +107,8 @@ def async_set_temperature(hass, temperature=None, entity_id=None,
] if value is not None
}
_LOGGER.debug("set_temperature start data=%s", kwargs)
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs))
await hass.services.async_call(
DOMAIN, SERVICE_SET_TEMPERATURE, kwargs, blocking=True)
@bind_hass
@@ -138,17 +129,15 @@ def set_temperature(hass, temperature=None, entity_id=None,
hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, kwargs)
@callback
@bind_hass
def async_set_humidity(hass, humidity, entity_id=None):
async def async_set_humidity(hass, humidity, entity_id=None):
"""Set new target humidity."""
data = {ATTR_HUMIDITY: humidity}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_HUMIDITY, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_HUMIDITY, data, blocking=True)
@bind_hass
@@ -162,17 +151,15 @@ def set_humidity(hass, humidity, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_HUMIDITY, data)
@callback
@bind_hass
def async_set_fan_mode(hass, fan, entity_id=None):
async def async_set_fan_mode(hass, fan, entity_id=None):
"""Set all or specified climate devices fan mode on."""
data = {ATTR_FAN_MODE: fan}
if entity_id:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_FAN_MODE, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_FAN_MODE, data, blocking=True)
@bind_hass
@@ -186,17 +173,15 @@ def set_fan_mode(hass, fan, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data)
@callback
@bind_hass
def async_set_operation_mode(hass, operation_mode, entity_id=None):
async def async_set_operation_mode(hass, operation_mode, entity_id=None):
"""Set new target operation mode."""
data = {ATTR_OPERATION_MODE: operation_mode}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_OPERATION_MODE, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_OPERATION_MODE, data, blocking=True)
@bind_hass
@@ -210,17 +195,15 @@ def set_operation_mode(hass, operation_mode, entity_id=None):
hass.services.call(DOMAIN, SERVICE_SET_OPERATION_MODE, data)
@callback
@bind_hass
def async_set_swing_mode(hass, swing_mode, entity_id=None):
async def async_set_swing_mode(hass, swing_mode, entity_id=None):
"""Set new target swing mode."""
data = {ATTR_SWING_MODE: swing_mode}
if entity_id is not None:
data[ATTR_ENTITY_ID] = entity_id
hass.async_create_task(
hass.services.async_call(DOMAIN, SERVICE_SET_SWING_MODE, data))
await hass.services.async_call(
DOMAIN, SERVICE_SET_SWING_MODE, data, blocking=True)
@bind_hass