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

+6 -10
View File
@@ -6,7 +6,6 @@ components. Instead call the service directly.
from homeassistant.components.switch import DOMAIN
from homeassistant.const import (
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON)
from homeassistant.core import callback
from homeassistant.loader import bind_hass
@@ -16,12 +15,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 switch 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
@@ -30,10 +28,8 @@ 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 switch 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)
+5 -10
View File
@@ -37,20 +37,17 @@ async def test_light_service_calls(hass):
assert hass.states.get('light.light_switch').state == 'on'
common.async_toggle(hass, 'light.light_switch')
await hass.async_block_till_done()
await common.async_toggle(hass, 'light.light_switch')
assert hass.states.get('switch.decorative_lights').state == 'off'
assert hass.states.get('light.light_switch').state == 'off'
common.async_turn_on(hass, 'light.light_switch')
await hass.async_block_till_done()
await common.async_turn_on(hass, 'light.light_switch')
assert hass.states.get('switch.decorative_lights').state == 'on'
assert hass.states.get('light.light_switch').state == 'on'
common.async_turn_off(hass, 'light.light_switch')
await hass.async_block_till_done()
await common.async_turn_off(hass, 'light.light_switch')
assert hass.states.get('switch.decorative_lights').state == 'off'
assert hass.states.get('light.light_switch').state == 'off'
@@ -68,14 +65,12 @@ async def test_switch_service_calls(hass):
assert hass.states.get('light.light_switch').state == 'on'
switch_common.async_turn_off(hass, 'switch.decorative_lights')
await hass.async_block_till_done()
await switch_common.async_turn_off(hass, 'switch.decorative_lights')
assert hass.states.get('switch.decorative_lights').state == 'off'
assert hass.states.get('light.light_switch').state == 'off'
switch_common.async_turn_on(hass, 'switch.decorative_lights')
await hass.async_block_till_done()
await switch_common.async_turn_on(hass, 'switch.decorative_lights')
assert hass.states.get('switch.decorative_lights').state == 'on'
assert hass.states.get('light.light_switch').state == 'on'