2016-08-24 01:23:18 +00:00
|
|
|
"""The tests for the Rfxtrx cover platform."""
|
2020-07-05 20:41:11 +00:00
|
|
|
from unittest.mock import call
|
2016-09-28 07:05:38 +00:00
|
|
|
|
2020-07-21 22:01:31 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from homeassistant.core import State
|
2020-07-03 08:22:02 +00:00
|
|
|
from homeassistant.setup import async_setup_component
|
2016-08-24 01:23:18 +00:00
|
|
|
|
2020-07-03 08:22:02 +00:00
|
|
|
from . import _signal_event
|
2016-08-24 01:23:18 +00:00
|
|
|
|
2020-07-21 22:01:31 +00:00
|
|
|
from tests.common import mock_restore_cache
|
|
|
|
|
2020-07-03 08:22:02 +00:00
|
|
|
|
|
|
|
async def test_one_cover(hass, rfxtrx):
|
|
|
|
"""Test with 1 cover."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
2020-07-12 20:03:22 +00:00
|
|
|
"rfxtrx",
|
2020-07-13 01:40:45 +00:00
|
|
|
{"rfxtrx": {"device": "abcd", "devices": {"0b1400cd0213c7f20d010f51": {}}}},
|
2020-07-03 08:22:02 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
|
|
|
assert state
|
2020-07-05 20:41:11 +00:00
|
|
|
|
|
|
|
await hass.services.async_call(
|
2020-07-12 20:03:22 +00:00
|
|
|
"cover",
|
|
|
|
"open_cover",
|
|
|
|
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
|
|
|
blocking=True,
|
2020-07-05 20:41:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
2020-07-12 20:03:22 +00:00
|
|
|
"cover",
|
|
|
|
"close_cover",
|
|
|
|
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
|
|
|
blocking=True,
|
2020-07-05 20:41:11 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
await hass.services.async_call(
|
2020-07-12 20:03:22 +00:00
|
|
|
"cover",
|
|
|
|
"stop_cover",
|
|
|
|
{"entity_id": "cover.lightwaverf_siemens_0213c7_242"},
|
|
|
|
blocking=True,
|
2020-07-03 08:22:02 +00:00
|
|
|
)
|
|
|
|
|
2020-07-05 20:41:11 +00: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 08:22:02 +00:00
|
|
|
|
|
|
|
|
2020-07-21 22:01:31 +00:00
|
|
|
@pytest.mark.parametrize("state", ["open", "closed"])
|
|
|
|
async def test_state_restore(hass, rfxtrx, state):
|
|
|
|
"""State restoration."""
|
|
|
|
|
|
|
|
entity_id = "cover.lightwaverf_siemens_0213c7_242"
|
|
|
|
|
|
|
|
mock_restore_cache(hass, [State(entity_id, state)])
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
|
|
|
"rfxtrx",
|
|
|
|
{"rfxtrx": {"device": "abcd", "devices": {"0b1400cd0213c7f20d010f51": {}}}},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
assert hass.states.get(entity_id).state == state
|
|
|
|
|
|
|
|
|
2020-07-03 08:22:02 +00:00
|
|
|
async def test_several_covers(hass, rfxtrx):
|
|
|
|
"""Test with 3 covers."""
|
|
|
|
assert await async_setup_component(
|
|
|
|
hass,
|
2020-07-12 20:03:22 +00:00
|
|
|
"rfxtrx",
|
2020-07-03 08:22:02 +00:00
|
|
|
{
|
2020-07-12 20:03:22 +00:00
|
|
|
"rfxtrx": {
|
|
|
|
"device": "abcd",
|
2020-07-03 08:22:02 +00:00
|
|
|
"devices": {
|
2020-07-12 20:03:22 +00:00
|
|
|
"0b1400cd0213c7f20d010f51": {},
|
|
|
|
"0A1400ADF394AB010D0060": {},
|
|
|
|
"09190000009ba8010100": {},
|
2020-07-03 08:22:02 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.lightwaverf_siemens_0213c7_242")
|
2020-07-05 20:41:11 +00:00
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
2020-07-12 20:03:22 +00:00
|
|
|
assert state.attributes.get("friendly_name") == "LightwaveRF, Siemens 0213c7:242"
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.lightwaverf_siemens_f394ab_1")
|
2020-07-05 20:41:11 +00:00
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
2020-07-12 20:03:22 +00:00
|
|
|
assert state.attributes.get("friendly_name") == "LightwaveRF, Siemens f394ab:1"
|
2020-07-05 20:41:11 +00:00
|
|
|
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.rollertrol_009ba8_1")
|
2020-07-05 20:41:11 +00:00
|
|
|
assert state
|
|
|
|
assert state.state == "closed"
|
2020-07-12 20:03:22 +00:00
|
|
|
assert state.attributes.get("friendly_name") == "RollerTrol 009ba8:1"
|
2020-07-03 08:22:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def test_discover_covers(hass, rfxtrx):
|
|
|
|
"""Test with discovery of covers."""
|
|
|
|
assert await async_setup_component(
|
2020-07-13 01:40:45 +00:00
|
|
|
hass, "rfxtrx", {"rfxtrx": {"device": "abcd", "automatic_add": True}}
|
2020-07-03 08:22:02 +00:00
|
|
|
)
|
|
|
|
await hass.async_block_till_done()
|
2020-07-13 00:57:19 +00:00
|
|
|
await hass.async_start()
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-07-05 20:41:11 +00:00
|
|
|
await _signal_event(hass, "0a140002f38cae010f0070")
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.lightwaverf_siemens_f38cae_1")
|
|
|
|
assert state
|
|
|
|
assert state.state == "open"
|
2020-07-03 08:22:02 +00:00
|
|
|
|
2020-07-05 20:41:11 +00:00
|
|
|
await _signal_event(hass, "0a1400adf394ab020e0060")
|
2020-07-12 20:03:22 +00:00
|
|
|
state = hass.states.get("cover.lightwaverf_siemens_f394ab_2")
|
|
|
|
assert state
|
|
|
|
assert state.state == "open"
|