Clean up RFLink tests and add two tests (#19511)
* some minor tests refactor * unused import
This commit is contained in:
parent
3a3d488de3
commit
fb226e3e3b
5 changed files with 136 additions and 143 deletions
|
@ -5,8 +5,6 @@ control of Rflink switch devices.
|
|||
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_OFF)
|
||||
|
@ -34,11 +32,10 @@ CONFIG = {
|
|||
}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_default_setup(hass, monkeypatch):
|
||||
async def test_default_setup(hass, monkeypatch):
|
||||
"""Test all basic functionality of the rflink switch component."""
|
||||
# setup mocking rflink module
|
||||
event_callback, create, protocol, _ = yield from mock_rflink(
|
||||
event_callback, create, protocol, _ = await mock_rflink(
|
||||
hass, CONFIG, DOMAIN, monkeypatch)
|
||||
|
||||
# make sure arguments are passed
|
||||
|
@ -57,7 +54,7 @@ def test_default_setup(hass, monkeypatch):
|
|||
'id': 'protocol_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
switch_after_first_command = hass.states.get('switch.test')
|
||||
assert switch_after_first_command.state == 'on'
|
||||
|
@ -69,7 +66,7 @@ def test_default_setup(hass, monkeypatch):
|
|||
'id': 'protocol_0_0',
|
||||
'command': 'off',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get('switch.test').state == 'off'
|
||||
|
||||
|
@ -79,7 +76,7 @@ def test_default_setup(hass, monkeypatch):
|
|||
'id': 'test_alias_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get('switch.test').state == 'on'
|
||||
|
||||
|
@ -87,24 +84,23 @@ def test_default_setup(hass, monkeypatch):
|
|||
# events because every new unknown device is added as a light by default.
|
||||
|
||||
# test changing state from HA propagates to Rflink
|
||||
hass.async_add_job(
|
||||
hass.async_create_task(
|
||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
assert protocol.send_command_ack.call_args_list[0][0][0] == 'protocol_0_0'
|
||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'off'
|
||||
|
||||
hass.async_add_job(
|
||||
hass.async_create_task(
|
||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_group_alias(hass, monkeypatch):
|
||||
async def test_group_alias(hass, monkeypatch):
|
||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -122,7 +118,7 @@ def test_group_alias(hass, monkeypatch):
|
|||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
event_callback, _, _, _ = await mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
@ -132,7 +128,7 @@ def test_group_alias(hass, monkeypatch):
|
|||
'id': 'test_group_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
@ -141,13 +137,12 @@ def test_group_alias(hass, monkeypatch):
|
|||
'id': 'test_group_0_0',
|
||||
'command': 'off',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_nogroup_alias(hass, monkeypatch):
|
||||
async def test_nogroup_alias(hass, monkeypatch):
|
||||
"""Non group aliases should not respond to group commands."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -165,7 +160,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
event_callback, _, _, _ = await mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
@ -175,7 +170,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||
'id': 'test_nogroup_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
# should not affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
|
@ -184,13 +179,12 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||
'id': 'test_nogroup_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
# should affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_nogroup_device_id(hass, monkeypatch):
|
||||
async def test_nogroup_device_id(hass, monkeypatch):
|
||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -208,7 +202,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
event_callback, _, _, _ = await mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
@ -218,7 +212,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||
'id': 'test_nogroup_0_0',
|
||||
'command': 'allon',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
# should not affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||
|
||||
|
@ -227,13 +221,12 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||
'id': 'test_nogroup_0_0',
|
||||
'command': 'on',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
# should affect state
|
||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_device_defaults(hass, monkeypatch):
|
||||
async def test_device_defaults(hass, monkeypatch):
|
||||
"""Event should fire if device_defaults config says so."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -254,7 +247,7 @@ def test_device_defaults(hass, monkeypatch):
|
|||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
event_callback, _, _, _ = await mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
calls = []
|
||||
|
@ -269,13 +262,12 @@ def test_device_defaults(hass, monkeypatch):
|
|||
'id': 'protocol_0_0',
|
||||
'command': 'off',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert calls[0].data == {'state': 'off', 'entity_id': DOMAIN + '.test'}
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_not_firing_default(hass, monkeypatch):
|
||||
async def test_not_firing_default(hass, monkeypatch):
|
||||
"""By default no bus events should be fired."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -293,7 +285,7 @@ def test_not_firing_default(hass, monkeypatch):
|
|||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
event_callback, _, _, _ = yield from mock_rflink(
|
||||
event_callback, _, _, _ = await mock_rflink(
|
||||
hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
calls = []
|
||||
|
@ -308,13 +300,12 @@ def test_not_firing_default(hass, monkeypatch):
|
|||
'id': 'protocol_0_0',
|
||||
'command': 'off',
|
||||
})
|
||||
yield from hass.async_block_till_done()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert not calls, 'an event has been fired'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_restore_state(hass, monkeypatch):
|
||||
async def test_restore_state(hass, monkeypatch):
|
||||
"""Ensure states are restored on startup."""
|
||||
config = {
|
||||
'rflink': {
|
||||
|
@ -329,6 +320,9 @@ def test_restore_state(hass, monkeypatch):
|
|||
},
|
||||
'switch_test': {
|
||||
'name': 's2',
|
||||
},
|
||||
'switch_s3': {
|
||||
'name': 's3',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +336,7 @@ def test_restore_state(hass, monkeypatch):
|
|||
hass.state = CoreState.starting
|
||||
|
||||
# setup mocking rflink module
|
||||
_, _, _, _ = yield from mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||
|
||||
state = hass.states.get(DOMAIN + '.s1')
|
||||
assert state
|
||||
|
@ -351,3 +345,9 @@ def test_restore_state(hass, monkeypatch):
|
|||
state = hass.states.get(DOMAIN + '.s2')
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
|
||||
# not cached switch must default values
|
||||
state = hass.states.get(DOMAIN + '.s3')
|
||||
assert state
|
||||
assert state.state == STATE_OFF
|
||||
assert state.attributes['assumed_state']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue