mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Clean up RFLink tests and add two tests (#19511)
* some minor tests refactor * unused import
This commit is contained in:
parent
3a3d488de3
commit
fb226e3e3b
@ -7,7 +7,6 @@ automatic sensor creation.
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from ..test_rflink import mock_rflink
|
|
||||||
from homeassistant.components.rflink import (
|
from homeassistant.components.rflink import (
|
||||||
CONF_RECONNECT_INTERVAL)
|
CONF_RECONNECT_INTERVAL)
|
||||||
|
|
||||||
@ -17,6 +16,7 @@ from homeassistant.const import (
|
|||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from tests.common import async_fire_time_changed
|
from tests.common import async_fire_time_changed
|
||||||
|
from ..test_rflink import mock_rflink
|
||||||
|
|
||||||
DOMAIN = 'binary_sensor'
|
DOMAIN = 'binary_sensor'
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ CONFIG = {
|
|||||||
async def test_default_setup(hass, monkeypatch):
|
async def test_default_setup(hass, monkeypatch):
|
||||||
"""Test all basic functionality of the rflink sensor component."""
|
"""Test all basic functionality of the rflink sensor component."""
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, create, _, disconnect_callback = await mock_rflink(
|
event_callback, create, _, _ = await mock_rflink(
|
||||||
hass, CONFIG, DOMAIN, monkeypatch)
|
hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# make sure arguments are passed
|
# make sure arguments are passed
|
||||||
@ -86,7 +86,7 @@ async def test_entity_availability(hass, monkeypatch):
|
|||||||
config[CONF_RECONNECT_INTERVAL] = 60
|
config[CONF_RECONNECT_INTERVAL] = 60
|
||||||
|
|
||||||
# Create platform and entities
|
# Create platform and entities
|
||||||
event_callback, create, _, disconnect_callback = await mock_rflink(
|
_, _, _, disconnect_callback = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch, failures=failures)
|
hass, config, DOMAIN, monkeypatch, failures=failures)
|
||||||
|
|
||||||
# Entities are available by default
|
# Entities are available by default
|
||||||
@ -114,7 +114,7 @@ async def test_entity_availability(hass, monkeypatch):
|
|||||||
async def test_off_delay(hass, monkeypatch):
|
async def test_off_delay(hass, monkeypatch):
|
||||||
"""Test off_delay option."""
|
"""Test off_delay option."""
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, create, _, disconnect_callback = await mock_rflink(
|
event_callback, create, _, _ = await mock_rflink(
|
||||||
hass, CONFIG, DOMAIN, monkeypatch)
|
hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# make sure arguments are passed
|
# make sure arguments are passed
|
||||||
|
@ -5,8 +5,6 @@ control of RFLink switch devices.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||||
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -43,11 +41,10 @@ CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_default_setup(hass, monkeypatch):
|
||||||
def test_default_setup(hass, monkeypatch):
|
|
||||||
"""Test all basic functionality of the RFLink switch component."""
|
"""Test all basic functionality of the RFLink switch component."""
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, create, protocol, _ = yield from mock_rflink(
|
event_callback, create, protocol, _ = await mock_rflink(
|
||||||
hass, CONFIG, DOMAIN, monkeypatch)
|
hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# make sure arguments are passed
|
# make sure arguments are passed
|
||||||
@ -66,7 +63,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
light_after_first_command = hass.states.get(DOMAIN + '.test')
|
light_after_first_command = hass.states.get(DOMAIN + '.test')
|
||||||
assert light_after_first_command.state == 'on'
|
assert light_after_first_command.state == 'on'
|
||||||
@ -78,26 +75,26 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
# should repond to group command
|
# should respond to group command
|
||||||
event_callback({
|
event_callback({
|
||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
light_after_first_command = hass.states.get(DOMAIN + '.test')
|
light_after_first_command = hass.states.get(DOMAIN + '.test')
|
||||||
assert light_after_first_command.state == 'on'
|
assert light_after_first_command.state == 'on'
|
||||||
|
|
||||||
# should repond to group command
|
# should respond to group command
|
||||||
event_callback({
|
event_callback({
|
||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'alloff',
|
'command': 'alloff',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
@ -107,7 +104,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'test_alias_0_0',
|
'id': 'test_alias_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
@ -116,23 +113,23 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'protocol2_0_1',
|
'id': 'protocol2_0_1',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.protocol2_0_1').state == 'on'
|
assert hass.states.get(DOMAIN + '.protocol2_0_1').state == 'on'
|
||||||
|
|
||||||
# test changing state from HA propagates to RFLink
|
# test changing state from HA propagates to RFLink
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{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 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][0] == 'protocol_0_0'
|
||||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'off'
|
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,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{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 hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
||||||
|
|
||||||
@ -141,11 +138,11 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'newkaku_0_1',
|
'id': 'newkaku_0_1',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.newkaku_0_1'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.newkaku_0_1'}))
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# dimmable should send highest dim level when turning on
|
# dimmable should send highest dim level when turning on
|
||||||
assert protocol.send_command_ack.call_args_list[2][0][1] == '15'
|
assert protocol.send_command_ack.call_args_list[2][0][1] == '15'
|
||||||
@ -153,29 +150,28 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
# and send on command for fallback
|
# and send on command for fallback
|
||||||
assert protocol.send_command_ack.call_args_list[3][0][1] == 'on'
|
assert protocol.send_command_ack.call_args_list[3][0][1] == 'on'
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: DOMAIN + '.newkaku_0_1',
|
ATTR_ENTITY_ID: DOMAIN + '.newkaku_0_1',
|
||||||
ATTR_BRIGHTNESS: 128,
|
ATTR_BRIGHTNESS: 128,
|
||||||
}))
|
}))
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_args_list[4][0][1] == '7'
|
assert protocol.send_command_ack.call_args_list[4][0][1] == '7'
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: DOMAIN + '.dim_test',
|
ATTR_ENTITY_ID: DOMAIN + '.dim_test',
|
||||||
ATTR_BRIGHTNESS: 128,
|
ATTR_BRIGHTNESS: 128,
|
||||||
}))
|
}))
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_args_list[5][0][1] == '7'
|
assert protocol.send_command_ack.call_args_list[5][0][1] == '7'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_firing_bus_event(hass, monkeypatch):
|
||||||
def test_firing_bus_event(hass, monkeypatch):
|
|
||||||
"""Incoming RFLink command events should be put on the HA event bus."""
|
"""Incoming RFLink command events should be put on the HA event bus."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -194,7 +190,7 @@ def test_firing_bus_event(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -209,13 +205,12 @@ def test_firing_bus_event(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'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'}
|
assert calls[0].data == {'state': 'off', 'entity_id': DOMAIN + '.test'}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_signal_repetitions(hass, monkeypatch):
|
||||||
def test_signal_repetitions(hass, monkeypatch):
|
|
||||||
"""Command should be sent amount of configured repetitions."""
|
"""Command should be sent amount of configured repetitions."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -242,26 +237,26 @@ def test_signal_repetitions(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, protocol, _ = yield from mock_rflink(
|
event_callback, _, protocol, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# test if signal repetition is performed according to configuration
|
# test if signal repetition is performed according to configuration
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||||
|
|
||||||
# wait for commands and repetitions to finish
|
# wait for commands and repetitions to finish
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_count == 2
|
assert protocol.send_command_ack.call_count == 2
|
||||||
|
|
||||||
# test if default apply to configured devices
|
# test if default apply to configured devices
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test1'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test1'}))
|
||||||
|
|
||||||
# wait for commands and repetitions to finish
|
# wait for commands and repetitions to finish
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_count == 5
|
assert protocol.send_command_ack.call_count == 5
|
||||||
|
|
||||||
@ -272,20 +267,19 @@ def test_signal_repetitions(hass, monkeypatch):
|
|||||||
})
|
})
|
||||||
|
|
||||||
# make sure entity is created before setting state
|
# make sure entity is created before setting state
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.protocol_0_2'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.protocol_0_2'}))
|
||||||
|
|
||||||
# wait for commands and repetitions to finish
|
# wait for commands and repetitions to finish
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_count == 8
|
assert protocol.send_command_ack.call_count == 8
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_signal_repetitions_alternation(hass, monkeypatch):
|
||||||
def test_signal_repetitions_alternation(hass, monkeypatch):
|
|
||||||
"""Simultaneously switching entities must alternate repetitions."""
|
"""Simultaneously switching entities must alternate repetitions."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -307,17 +301,17 @@ def test_signal_repetitions_alternation(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, protocol, _ = yield from mock_rflink(
|
_, _, protocol, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test1'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test1'}))
|
||||||
|
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_args_list[0][0][0] == 'protocol_0_0'
|
assert protocol.send_command_ack.call_args_list[0][0][0] == 'protocol_0_0'
|
||||||
assert protocol.send_command_ack.call_args_list[1][0][0] == 'protocol_0_1'
|
assert protocol.send_command_ack.call_args_list[1][0][0] == 'protocol_0_1'
|
||||||
@ -325,8 +319,7 @@ def test_signal_repetitions_alternation(hass, monkeypatch):
|
|||||||
assert protocol.send_command_ack.call_args_list[3][0][0] == 'protocol_0_1'
|
assert protocol.send_command_ack.call_args_list[3][0][0] == 'protocol_0_1'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_signal_repetitions_cancelling(hass, monkeypatch):
|
||||||
def test_signal_repetitions_cancelling(hass, monkeypatch):
|
|
||||||
"""Cancel outstanding repetitions when state changed."""
|
"""Cancel outstanding repetitions when state changed."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -344,18 +337,18 @@ def test_signal_repetitions_cancelling(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, protocol, _ = yield from mock_rflink(
|
_, _, protocol, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||||
|
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
||||||
|
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'on'
|
assert protocol.send_command_ack.call_args_list[0][0][1] == 'on'
|
||||||
assert protocol.send_command_ack.call_args_list[1][0][1] == 'off'
|
assert protocol.send_command_ack.call_args_list[1][0][1] == 'off'
|
||||||
@ -363,8 +356,7 @@ def test_signal_repetitions_cancelling(hass, monkeypatch):
|
|||||||
assert protocol.send_command_ack.call_args_list[3][0][1] == 'off'
|
assert protocol.send_command_ack.call_args_list[3][0][1] == 'off'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_type_toggle(hass, monkeypatch):
|
||||||
def test_type_toggle(hass, monkeypatch):
|
|
||||||
"""Test toggle type lights (on/on)."""
|
"""Test toggle type lights (on/on)."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -382,7 +374,7 @@ def test_type_toggle(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.toggle_test').state == 'off'
|
assert hass.states.get(DOMAIN + '.toggle_test').state == 'off'
|
||||||
@ -392,7 +384,7 @@ def test_type_toggle(hass, monkeypatch):
|
|||||||
'id': 'toggle_0_0',
|
'id': 'toggle_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.toggle_test').state == 'on'
|
assert hass.states.get(DOMAIN + '.toggle_test').state == 'on'
|
||||||
|
|
||||||
@ -401,13 +393,12 @@ def test_type_toggle(hass, monkeypatch):
|
|||||||
'id': 'toggle_0_0',
|
'id': 'toggle_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.toggle_test').state == 'off'
|
assert hass.states.get(DOMAIN + '.toggle_test').state == 'off'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_group_alias(hass, monkeypatch):
|
||||||
def test_group_alias(hass, monkeypatch):
|
|
||||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -425,7 +416,7 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -435,7 +426,7 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
'id': 'test_group_0_0',
|
'id': 'test_group_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
@ -444,13 +435,12 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
'id': 'test_group_0_0',
|
'id': 'test_group_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_nogroup_alias(hass, monkeypatch):
|
||||||
def test_nogroup_alias(hass, monkeypatch):
|
|
||||||
"""Non group aliases should not respond to group commands."""
|
"""Non group aliases should not respond to group commands."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -468,7 +458,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -478,7 +468,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should not affect state
|
# should not affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
@ -487,13 +477,12 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should affect state
|
# should affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_nogroup_device_id(hass, monkeypatch):
|
||||||
def test_nogroup_device_id(hass, monkeypatch):
|
|
||||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -511,7 +500,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -521,7 +510,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should not affect state
|
# should not affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
@ -530,13 +519,12 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should affect state
|
# should affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_disable_automatic_add(hass, monkeypatch):
|
||||||
def test_disable_automatic_add(hass, monkeypatch):
|
|
||||||
"""If disabled new devices should not be automatically added."""
|
"""If disabled new devices should not be automatically added."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -549,7 +537,7 @@ def test_disable_automatic_add(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# test event for new unconfigured sensor
|
# test event for new unconfigured sensor
|
||||||
@ -557,14 +545,13 @@ def test_disable_automatic_add(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# make sure new device is not added
|
# make sure new device is not added
|
||||||
assert not hass.states.get(DOMAIN + '.protocol_0_0')
|
assert not hass.states.get(DOMAIN + '.protocol_0_0')
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_restore_state(hass, monkeypatch):
|
||||||
def test_restore_state(hass, monkeypatch):
|
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -583,6 +570,10 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
'test_restore_3': {
|
'test_restore_3': {
|
||||||
'name': 'l3',
|
'name': 'l3',
|
||||||
},
|
},
|
||||||
|
'test_restore_4': {
|
||||||
|
'name': 'l4',
|
||||||
|
'type': 'dimmable',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -596,7 +587,7 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
hass.state = CoreState.starting
|
hass.state = CoreState.starting
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, _, _, _ = yield from mock_rflink(hass, config, DOMAIN, monkeypatch)
|
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# dimmable light must restore brightness
|
# dimmable light must restore brightness
|
||||||
state = hass.states.get(DOMAIN + '.l1')
|
state = hass.states.get(DOMAIN + '.l1')
|
||||||
@ -614,3 +605,10 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
state = hass.states.get(DOMAIN + '.l3')
|
state = hass.states.get(DOMAIN + '.l3')
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
|
|
||||||
|
# not cached light must default values
|
||||||
|
state = hass.states.get(DOMAIN + '.l4')
|
||||||
|
assert state
|
||||||
|
assert state.state == STATE_OFF
|
||||||
|
assert not state.attributes.get(ATTR_BRIGHTNESS)
|
||||||
|
assert state.attributes['assumed_state']
|
||||||
|
@ -5,12 +5,10 @@ automatic sensor creation.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from ..test_rflink import mock_rflink
|
|
||||||
from homeassistant.components.rflink import (
|
from homeassistant.components.rflink import (
|
||||||
CONF_RECONNECT_INTERVAL)
|
CONF_RECONNECT_INTERVAL)
|
||||||
from homeassistant.const import STATE_UNKNOWN
|
from homeassistant.const import STATE_UNKNOWN
|
||||||
|
from ..test_rflink import mock_rflink
|
||||||
|
|
||||||
DOMAIN = 'sensor'
|
DOMAIN = 'sensor'
|
||||||
|
|
||||||
@ -31,11 +29,10 @@ CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_default_setup(hass, monkeypatch):
|
||||||
def test_default_setup(hass, monkeypatch):
|
|
||||||
"""Test all basic functionality of the rflink sensor component."""
|
"""Test all basic functionality of the rflink sensor component."""
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, create, _, disconnect_callback = yield from mock_rflink(
|
event_callback, create, _, _ = await mock_rflink(
|
||||||
hass, CONFIG, DOMAIN, monkeypatch)
|
hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# make sure arguments are passed
|
# make sure arguments are passed
|
||||||
@ -54,7 +51,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'value': 1,
|
'value': 1,
|
||||||
'unit': '°C',
|
'unit': '°C',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get('sensor.test').state == '1'
|
assert hass.states.get('sensor.test').state == '1'
|
||||||
|
|
||||||
@ -65,7 +62,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'value': 0,
|
'value': 0,
|
||||||
'unit': '°C',
|
'unit': '°C',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# test state of new sensor
|
# test state of new sensor
|
||||||
new_sensor = hass.states.get('sensor.test2')
|
new_sensor = hass.states.get('sensor.test2')
|
||||||
@ -75,8 +72,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
assert new_sensor.attributes['icon'] == 'mdi:thermometer'
|
assert new_sensor.attributes['icon'] == 'mdi:thermometer'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_disable_automatic_add(hass, monkeypatch):
|
||||||
def test_disable_automatic_add(hass, monkeypatch):
|
|
||||||
"""If disabled new devices should not be automatically added."""
|
"""If disabled new devices should not be automatically added."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -89,7 +85,7 @@ def test_disable_automatic_add(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# test event for new unconfigured sensor
|
# test event for new unconfigured sensor
|
||||||
@ -99,14 +95,13 @@ def test_disable_automatic_add(hass, monkeypatch):
|
|||||||
'value': 0,
|
'value': 0,
|
||||||
'unit': '°C',
|
'unit': '°C',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# make sure new device is not added
|
# make sure new device is not added
|
||||||
assert not hass.states.get('sensor.test2')
|
assert not hass.states.get('sensor.test2')
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_entity_availability(hass, monkeypatch):
|
||||||
def test_entity_availability(hass, monkeypatch):
|
|
||||||
"""If Rflink device is disconnected, entities should become unavailable."""
|
"""If Rflink device is disconnected, entities should become unavailable."""
|
||||||
# Make sure Rflink mock does not 'recover' to quickly from the
|
# Make sure Rflink mock does not 'recover' to quickly from the
|
||||||
# disconnect or else the unavailability cannot be measured
|
# disconnect or else the unavailability cannot be measured
|
||||||
@ -115,7 +110,7 @@ def test_entity_availability(hass, monkeypatch):
|
|||||||
config[CONF_RECONNECT_INTERVAL] = 60
|
config[CONF_RECONNECT_INTERVAL] = 60
|
||||||
|
|
||||||
# Create platform and entities
|
# Create platform and entities
|
||||||
event_callback, create, _, disconnect_callback = yield from mock_rflink(
|
_, _, _, disconnect_callback = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch, failures=failures)
|
hass, config, DOMAIN, monkeypatch, failures=failures)
|
||||||
|
|
||||||
# Entities are available by default
|
# Entities are available by default
|
||||||
@ -125,7 +120,7 @@ def test_entity_availability(hass, monkeypatch):
|
|||||||
disconnect_callback()
|
disconnect_callback()
|
||||||
|
|
||||||
# Wait for dispatch events to propagate
|
# Wait for dispatch events to propagate
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Entity should be unavailable
|
# Entity should be unavailable
|
||||||
assert hass.states.get('sensor.test').state == 'unavailable'
|
assert hass.states.get('sensor.test').state == 'unavailable'
|
||||||
@ -134,7 +129,7 @@ def test_entity_availability(hass, monkeypatch):
|
|||||||
disconnect_callback()
|
disconnect_callback()
|
||||||
|
|
||||||
# Wait for dispatch events to propagate
|
# Wait for dispatch events to propagate
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
# Entities should be available again
|
# Entities should be available again
|
||||||
assert hass.states.get('sensor.test').state == STATE_UNKNOWN
|
assert hass.states.get('sensor.test').state == STATE_UNKNOWN
|
||||||
|
@ -5,8 +5,6 @@ control of Rflink switch devices.
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
|
|
||||||
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
from homeassistant.components.rflink import EVENT_BUTTON_PRESSED
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_OFF)
|
ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_ON, STATE_OFF)
|
||||||
@ -34,11 +32,10 @@ CONFIG = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_default_setup(hass, monkeypatch):
|
||||||
def test_default_setup(hass, monkeypatch):
|
|
||||||
"""Test all basic functionality of the rflink switch component."""
|
"""Test all basic functionality of the rflink switch component."""
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, create, protocol, _ = yield from mock_rflink(
|
event_callback, create, protocol, _ = await mock_rflink(
|
||||||
hass, CONFIG, DOMAIN, monkeypatch)
|
hass, CONFIG, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
# make sure arguments are passed
|
# make sure arguments are passed
|
||||||
@ -57,7 +54,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
switch_after_first_command = hass.states.get('switch.test')
|
switch_after_first_command = hass.states.get('switch.test')
|
||||||
assert switch_after_first_command.state == 'on'
|
assert switch_after_first_command.state == 'on'
|
||||||
@ -69,7 +66,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get('switch.test').state == 'off'
|
assert hass.states.get('switch.test').state == 'off'
|
||||||
|
|
||||||
@ -79,7 +76,7 @@ def test_default_setup(hass, monkeypatch):
|
|||||||
'id': 'test_alias_0_0',
|
'id': 'test_alias_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get('switch.test').state == 'on'
|
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.
|
# events because every new unknown device is added as a light by default.
|
||||||
|
|
||||||
# test changing state from HA propagates to Rflink
|
# test changing state from HA propagates to Rflink
|
||||||
hass.async_add_job(
|
hass.async_create_task(
|
||||||
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_OFF,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{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 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][0] == 'protocol_0_0'
|
||||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'off'
|
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,
|
hass.services.async_call(DOMAIN, SERVICE_TURN_ON,
|
||||||
{ATTR_ENTITY_ID: DOMAIN + '.test'}))
|
{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 hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
assert protocol.send_command_ack.call_args_list[1][0][1] == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_group_alias(hass, monkeypatch):
|
||||||
def test_group_alias(hass, monkeypatch):
|
|
||||||
"""Group aliases should only respond to group commands (allon/alloff)."""
|
"""Group aliases should only respond to group commands (allon/alloff)."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -122,7 +118,7 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -132,7 +128,7 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
'id': 'test_group_0_0',
|
'id': 'test_group_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
@ -141,13 +137,12 @@ def test_group_alias(hass, monkeypatch):
|
|||||||
'id': 'test_group_0_0',
|
'id': 'test_group_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_nogroup_alias(hass, monkeypatch):
|
||||||
def test_nogroup_alias(hass, monkeypatch):
|
|
||||||
"""Non group aliases should not respond to group commands."""
|
"""Non group aliases should not respond to group commands."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -165,7 +160,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -175,7 +170,7 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should not affect state
|
# should not affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
@ -184,13 +179,12 @@ def test_nogroup_alias(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should affect state
|
# should affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_nogroup_device_id(hass, monkeypatch):
|
||||||
def test_nogroup_device_id(hass, monkeypatch):
|
|
||||||
"""Device id that do not respond to group commands (allon/alloff)."""
|
"""Device id that do not respond to group commands (allon/alloff)."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -208,7 +202,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
@ -218,7 +212,7 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'allon',
|
'command': 'allon',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should not affect state
|
# should not affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
assert hass.states.get(DOMAIN + '.test').state == 'off'
|
||||||
|
|
||||||
@ -227,13 +221,12 @@ def test_nogroup_device_id(hass, monkeypatch):
|
|||||||
'id': 'test_nogroup_0_0',
|
'id': 'test_nogroup_0_0',
|
||||||
'command': 'on',
|
'command': 'on',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
# should affect state
|
# should affect state
|
||||||
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
assert hass.states.get(DOMAIN + '.test').state == 'on'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_device_defaults(hass, monkeypatch):
|
||||||
def test_device_defaults(hass, monkeypatch):
|
|
||||||
"""Event should fire if device_defaults config says so."""
|
"""Event should fire if device_defaults config says so."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -254,7 +247,7 @@ def test_device_defaults(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -269,13 +262,12 @@ def test_device_defaults(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'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'}
|
assert calls[0].data == {'state': 'off', 'entity_id': DOMAIN + '.test'}
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_not_firing_default(hass, monkeypatch):
|
||||||
def test_not_firing_default(hass, monkeypatch):
|
|
||||||
"""By default no bus events should be fired."""
|
"""By default no bus events should be fired."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -293,7 +285,7 @@ def test_not_firing_default(hass, monkeypatch):
|
|||||||
}
|
}
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
event_callback, _, _, _ = yield from mock_rflink(
|
event_callback, _, _, _ = await mock_rflink(
|
||||||
hass, config, DOMAIN, monkeypatch)
|
hass, config, DOMAIN, monkeypatch)
|
||||||
|
|
||||||
calls = []
|
calls = []
|
||||||
@ -308,13 +300,12 @@ def test_not_firing_default(hass, monkeypatch):
|
|||||||
'id': 'protocol_0_0',
|
'id': 'protocol_0_0',
|
||||||
'command': 'off',
|
'command': 'off',
|
||||||
})
|
})
|
||||||
yield from hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert not calls, 'an event has been fired'
|
assert not calls, 'an event has been fired'
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def test_restore_state(hass, monkeypatch):
|
||||||
def test_restore_state(hass, monkeypatch):
|
|
||||||
"""Ensure states are restored on startup."""
|
"""Ensure states are restored on startup."""
|
||||||
config = {
|
config = {
|
||||||
'rflink': {
|
'rflink': {
|
||||||
@ -329,6 +320,9 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
},
|
},
|
||||||
'switch_test': {
|
'switch_test': {
|
||||||
'name': 's2',
|
'name': 's2',
|
||||||
|
},
|
||||||
|
'switch_s3': {
|
||||||
|
'name': 's3',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,7 +336,7 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
hass.state = CoreState.starting
|
hass.state = CoreState.starting
|
||||||
|
|
||||||
# setup mocking rflink module
|
# 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')
|
state = hass.states.get(DOMAIN + '.s1')
|
||||||
assert state
|
assert state
|
||||||
@ -351,3 +345,9 @@ def test_restore_state(hass, monkeypatch):
|
|||||||
state = hass.states.get(DOMAIN + '.s2')
|
state = hass.states.get(DOMAIN + '.s2')
|
||||||
assert state
|
assert state
|
||||||
assert state.state == STATE_OFF
|
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']
|
||||||
|
@ -97,8 +97,8 @@ def test_send_no_wait(hass, monkeypatch):
|
|||||||
'platform': 'rflink',
|
'platform': 'rflink',
|
||||||
'devices': {
|
'devices': {
|
||||||
'protocol_0_0': {
|
'protocol_0_0': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'aliases': ['test_alias_0_0'],
|
'aliases': ['test_alias_0_0'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -129,8 +129,8 @@ def test_cover_send_no_wait(hass, monkeypatch):
|
|||||||
'platform': 'rflink',
|
'platform': 'rflink',
|
||||||
'devices': {
|
'devices': {
|
||||||
'RTS_0100F2_0': {
|
'RTS_0100F2_0': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'aliases': ['test_alias_0_0'],
|
'aliases': ['test_alias_0_0'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -274,8 +274,8 @@ def test_error_when_not_connected(hass, monkeypatch):
|
|||||||
'platform': 'rflink',
|
'platform': 'rflink',
|
||||||
'devices': {
|
'devices': {
|
||||||
'protocol_0_0': {
|
'protocol_0_0': {
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'aliases': ['test_alias_0_0'],
|
'aliases': ['test_alias_0_0'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -285,7 +285,7 @@ def test_error_when_not_connected(hass, monkeypatch):
|
|||||||
failures = [False, True, False]
|
failures = [False, True, False]
|
||||||
|
|
||||||
# setup mocking rflink module
|
# setup mocking rflink module
|
||||||
_, mock_create, _, disconnect_callback = yield from mock_rflink(
|
_, _, _, disconnect_callback = yield from mock_rflink(
|
||||||
hass, config, domain, monkeypatch, failures=failures)
|
hass, config, domain, monkeypatch, failures=failures)
|
||||||
|
|
||||||
# rflink initiated disconnect
|
# rflink initiated disconnect
|
||||||
|
Loading…
x
Reference in New Issue
Block a user