2016-08-24 03:23:18 +02:00
|
|
|
"""The tests for the Rfxtrx cover platform."""
|
2020-07-05 22:41:11 +02:00
|
|
|
from unittest.mock import call
|
2016-09-28 00:05:38 -07:00
|
|
|
|
2016-08-24 03:23:18 +02:00
|
|
|
from homeassistant.components import rfxtrx as rfxtrx_core
|
2020-07-03 10:22:02 +02:00
|
|
|
from homeassistant.setup import async_setup_component
|
2016-08-24 03:23:18 +02:00
|
|
|
|
2020-07-03 10:22:02 +02:00
|
|
|
from . import _signal_event
|
2016-08-24 03:23:18 +02:00
|
|
|
|
2020-07-03 10:22:02 +02:00
|
|
|
from tests.common import assert_setup_component
|
2016-08-24 03:23:18 +02:00
|
|
|
|
|
|
|
|
2020-07-03 10:22:02 +02:00
|
|
|
async def test_valid_config(hass, rfxtrx):
|
|
|
|
"""Test configuration."""
|
|
|
|
with assert_setup_component(1):
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
2019-07-31 12:25:30 -07:00
|
|
|
"cover",
|
|
|
|
{
|
|
|
|
"cover": {
|
|
|
|
"platform": "rfxtrx",
|
|
|
|
"automatic_add": True,
|
|
|
|
"devices": {
|
|
|
|
"0b1100cd0213c7f210010f51": {
|
|
|
|
"name": "Test",
|
2020-06-28 06:54:27 +02:00
|
|
|
rfxtrx_core.ATTR_FIRE_EVENT: True,
|
2019-07-31 12:25:30 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2020-07-03 10:22:02 +02:00
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
|
|
async def test_default_config(hass, rfxtrx):
|
|
|
|
"""Test with 0 cover."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass, "cover", {"cover": {"platform": "rfxtrx", "devices": {}}}
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
assert len(hass.states.async_all()) == 0
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_one_cover(hass, rfxtrx):
|
|
|
|
"""Test with 1 cover."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"cover",
|
|
|
|
{
|
|
|
|
"cover": {
|
|
|
|
"platform": "rfxtrx",
|
|
|
|
"devices": {"0b1400cd0213c7f210010f51": {"name": "Test"}},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
assert len(hass.states.async_all()) == 1
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"cover", "open_cover", {"entity_id": "cover.test"}, blocking=True
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"cover", "close_cover", {"entity_id": "cover.test"}, blocking=True
|
|
|
|
)
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
"cover", "stop_cover", {"entity_id": "cover.test"}, blocking=True
|
2020-07-03 10:22:02 +02:00
|
|
|
)
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
assert rfxtrx.transport.send.mock_calls == [
|
|
|
|
call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\x0f\x00\x00")),
|
|
|
|
call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\r\x00\x00")),
|
|
|
|
call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\x0e\x00\x00")),
|
|
|
|
]
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_several_covers(hass, rfxtrx):
|
|
|
|
"""Test with 3 covers."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"cover",
|
|
|
|
{
|
|
|
|
"cover": {
|
|
|
|
"platform": "rfxtrx",
|
|
|
|
"signal_repetitions": 3,
|
|
|
|
"devices": {
|
|
|
|
"0b1100cd0213c7f230010f71": {"name": "Test"},
|
|
|
|
"0b1100100118cdea02010f70": {"name": "Bath"},
|
|
|
|
"0b1100101118cdea02010f70": {"name": "Living"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
state = hass.states.get("cover.test")
|
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
|
|
|
assert state.attributes.get("friendly_name") == "Test"
|
2020-07-03 10:22:02 +02:00
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
state = hass.states.get("cover.bath")
|
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
|
|
|
assert state.attributes.get("friendly_name") == "Bath"
|
|
|
|
|
|
|
|
state = hass.states.get("cover.living")
|
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
|
|
|
assert state.attributes.get("friendly_name") == "Living"
|
|
|
|
|
|
|
|
assert len(hass.states.async_all()) == 3
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discover_covers(hass, rfxtrx):
|
|
|
|
"""Test with discovery of covers."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"cover",
|
|
|
|
{"cover": {"platform": "rfxtrx", "automatic_add": True, "devices": {}}},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a140002f38cae010f0070")
|
|
|
|
assert len(hass.states.async_all()) == 1
|
2020-07-03 10:22:02 +02:00
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a1400adf394ab020e0060")
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
# Trying to add a sensor
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a52085e070100b31b0279")
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
# Trying to add a light
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0b1100100118cdea02010f70")
|
|
|
|
assert len(hass.states.async_all()) == 2
|
2020-07-03 10:22:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discover_cover_noautoadd(hass, rfxtrx):
|
|
|
|
"""Test with discovery of cover when auto add is False."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"cover",
|
|
|
|
{"cover": {"platform": "rfxtrx", "automatic_add": False, "devices": {}}},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a1400adf394ab010d0060")
|
|
|
|
assert len(hass.states.async_all()) == 0
|
2020-07-03 10:22:02 +02:00
|
|
|
|
2020-07-05 22:41:11 +02:00
|
|
|
await _signal_event(hass, "0a1400adf394ab020e0060")
|
|
|
|
assert len(hass.states.async_all()) == 0
|