RFLink: Add send_command service (#8876)
Add an optional extended description…
This commit is contained in:
parent
3aceca9d8a
commit
62e86270e6
3 changed files with 106 additions and 5 deletions
|
@ -4,13 +4,15 @@ import asyncio
|
|||
from unittest.mock import Mock
|
||||
|
||||
from homeassistant.bootstrap import async_setup_component
|
||||
from homeassistant.components.rflink import CONF_RECONNECT_INTERVAL
|
||||
from homeassistant.components.rflink import (
|
||||
CONF_RECONNECT_INTERVAL, SERVICE_SEND_COMMAND)
|
||||
from homeassistant.const import ATTR_ENTITY_ID, SERVICE_TURN_OFF
|
||||
from tests.common import assert_setup_component
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_rflink(hass, config, domain, monkeypatch, failures=None):
|
||||
def mock_rflink(hass, config, domain, monkeypatch, failures=None,
|
||||
platform_count=1):
|
||||
"""Create mock Rflink asyncio protocol, test component setup."""
|
||||
transport, protocol = (Mock(), Mock())
|
||||
|
||||
|
@ -45,7 +47,7 @@ def mock_rflink(hass, config, domain, monkeypatch, failures=None):
|
|||
mock_create)
|
||||
|
||||
# verify instanstiation of component with given config
|
||||
with assert_setup_component(1, domain):
|
||||
with assert_setup_component(platform_count, domain):
|
||||
yield from async_setup_component(hass, domain, config)
|
||||
|
||||
# hook into mock config for injecting events
|
||||
|
@ -117,6 +119,58 @@ def test_send_no_wait(hass, monkeypatch):
|
|||
assert protocol.send_command.call_args_list[0][0][1] == 'off'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_send_command(hass, monkeypatch):
|
||||
"""Test send_command service."""
|
||||
domain = 'rflink'
|
||||
config = {
|
||||
'rflink': {
|
||||
'port': '/dev/ttyABC0',
|
||||
},
|
||||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
_, _, protocol, _ = yield from mock_rflink(
|
||||
hass, config, domain, monkeypatch, platform_count=5)
|
||||
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(domain, SERVICE_SEND_COMMAND,
|
||||
{'device_id': 'newkaku_0000c6c2_1',
|
||||
'command': 'on'}))
|
||||
yield from hass.async_block_till_done()
|
||||
assert (protocol.send_command_ack.call_args_list[0][0][0]
|
||||
== 'newkaku_0000c6c2_1')
|
||||
assert protocol.send_command_ack.call_args_list[0][0][1] == 'on'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_send_command_invalid_arguments(hass, monkeypatch):
|
||||
"""Test send_command service."""
|
||||
domain = 'rflink'
|
||||
config = {
|
||||
'rflink': {
|
||||
'port': '/dev/ttyABC0',
|
||||
},
|
||||
}
|
||||
|
||||
# setup mocking rflink module
|
||||
_, _, protocol, _ = yield from mock_rflink(
|
||||
hass, config, domain, monkeypatch, platform_count=5)
|
||||
|
||||
# one argument missing
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(domain, SERVICE_SEND_COMMAND,
|
||||
{'command': 'on'}))
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(domain, SERVICE_SEND_COMMAND,
|
||||
{'device_id': 'newkaku_0000c6c2_1'}))
|
||||
# no arguments
|
||||
hass.async_add_job(
|
||||
hass.services.async_call(domain, SERVICE_SEND_COMMAND, {}))
|
||||
yield from hass.async_block_till_done()
|
||||
assert protocol.send_command_ack.call_args_list == []
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
def test_reconnecting_after_disconnect(hass, monkeypatch):
|
||||
"""An unexpected disconnect should cause a reconnect."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue