Update RFLink tests (#48149)

This commit is contained in:
javicalle 2021-03-21 03:27:24 +01:00 committed by GitHub
parent 0193f16ae9
commit 99d2d72d13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 102 additions and 174 deletions

View file

@ -89,20 +89,16 @@ async def test_default_setup(hass, monkeypatch):
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
# test changing state from HA propagates to RFLink
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.test").state == STATE_CLOSED
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] == "DOWN"
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.test").state == STATE_OPEN
@ -162,10 +158,8 @@ async def test_signal_repetitions(hass, monkeypatch):
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
# test if signal repetition is performed according to configuration
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
# wait for commands and repetitions to finish
@ -174,10 +168,8 @@ async def test_signal_repetitions(hass, monkeypatch):
assert protocol.send_command_ack.call_count == 2
# test if default apply to configured devices
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
# wait for commands and repetitions to finish
@ -202,15 +194,11 @@ async def test_signal_repetitions_alternation(hass, monkeypatch):
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
await hass.async_block_till_done()
@ -234,16 +222,12 @@ async def test_signal_repetitions_cancelling(hass, monkeypatch):
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
@ -606,12 +590,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'DOWN' command sent to a non-newkaku device
# that has its type set to 'standard'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
await hass.async_block_till_done()
@ -623,12 +605,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'UP' command sent to a non-newkaku device
# that has its type set to 'standard'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
await hass.async_block_till_done()
@ -640,10 +620,8 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'DOWN' command sent to a non-newkaku device
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
await hass.async_block_till_done()
@ -655,10 +633,8 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'UP' command sent to a non-newkaku device
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
await hass.async_block_till_done()
@ -670,12 +646,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'UP' command sent to a non-newkaku device
# that has its type set to 'inverted'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
await hass.async_block_till_done()
@ -687,12 +661,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'DOWN' command sent to a non-newkaku device
# that has its type set to 'inverted'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
await hass.async_block_till_done()
@ -704,12 +676,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'DOWN' command sent to a newkaku device
# that has its type set to 'standard'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
await hass.async_block_till_done()
@ -721,12 +691,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'UP' command sent to a newkaku device
# that has its type set to 'standard'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
await hass.async_block_till_done()
@ -738,10 +706,8 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'UP' command sent to a newkaku device
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
await hass.async_block_till_done()
@ -753,10 +719,8 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'DOWN' command sent to a newkaku device
# that has its type not specified.
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
await hass.async_block_till_done()
@ -768,12 +732,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the close command from HA should result
# in an 'UP' command sent to a newkaku device
# that has its type set to 'inverted'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
await hass.async_block_till_done()
@ -785,12 +747,10 @@ async def test_inverted_cover(hass, monkeypatch):
# Sending the open command from HA should result
# in an 'DOWN' command sent to a newkaku device
# that has its type set to 'inverted'.
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
await hass.async_block_till_done()

View file

@ -107,10 +107,8 @@ async def test_send_no_wait(hass, monkeypatch):
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
hass.async_create_task(
hass.services.async_call(
domain, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "switch.test"}
)
await hass.services.async_call(
domain, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: "switch.test"}
)
await hass.async_block_till_done()
assert protocol.send_command.call_args_list[0][0][0] == "protocol_0_0"
@ -133,10 +131,8 @@ async def test_cover_send_no_wait(hass, monkeypatch):
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
hass.async_create_task(
hass.services.async_call(
domain, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: "cover.test"}
)
await hass.services.async_call(
domain, SERVICE_STOP_COVER, {ATTR_ENTITY_ID: "cover.test"}
)
await hass.async_block_till_done()
assert protocol.send_command.call_args_list[0][0][0] == "RTS_0100F2_0"
@ -151,12 +147,10 @@ async def test_send_command(hass, monkeypatch):
# setup mocking rflink module
_, _, protocol, _ = await mock_rflink(hass, config, domain, monkeypatch)
hass.async_create_task(
hass.services.async_call(
domain,
SERVICE_SEND_COMMAND,
{"device_id": "newkaku_0000c6c2_1", "command": "on"},
)
await hass.services.async_call(
domain,
SERVICE_SEND_COMMAND,
{"device_id": "newkaku_0000c6c2_1", "command": "on"},
)
await hass.async_block_till_done()
assert protocol.send_command_ack.call_args_list[0][0][0] == "newkaku_0000c6c2_1"
@ -215,24 +209,22 @@ async def test_send_command_event_propagation(hass, monkeypatch):
# default value = 'off'
assert hass.states.get(f"{domain}.test1").state == "off"
hass.async_create_task(
hass.services.async_call(
"rflink",
SERVICE_SEND_COMMAND,
{"device_id": "protocol_0_1", "command": "on"},
)
await hass.services.async_call(
"rflink",
SERVICE_SEND_COMMAND,
{"device_id": "protocol_0_1", "command": "on"},
blocking=True,
)
await hass.async_block_till_done()
assert protocol.send_command_ack.call_args_list[0][0][0] == "protocol_0_1"
assert protocol.send_command_ack.call_args_list[0][0][1] == "on"
assert hass.states.get(f"{domain}.test1").state == "on"
hass.async_create_task(
hass.services.async_call(
"rflink",
SERVICE_SEND_COMMAND,
{"device_id": "protocol_0_1", "command": "alloff"},
)
await hass.services.async_call(
"rflink",
SERVICE_SEND_COMMAND,
{"device_id": "protocol_0_1", "command": "alloff"},
blocking=True,
)
await hass.async_block_till_done()
assert protocol.send_command_ack.call_args_list[1][0][0] == "protocol_0_1"

View file

@ -96,20 +96,16 @@ async def test_default_setup(hass, monkeypatch):
assert hass.states.get(f"{DOMAIN}.protocol2_0_1").state == "on"
# test changing state from HA propagates to RFLink
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{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_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.test").state == "on"
@ -118,10 +114,8 @@ async def test_default_setup(hass, monkeypatch):
# protocols supporting dimming and on/off should create hybrid light entity
event_callback({"id": "newkaku_0_1", "command": "off"})
await hass.async_block_till_done()
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1"}
)
await hass.async_block_till_done()
@ -131,23 +125,19 @@ async def test_default_setup(hass, monkeypatch):
# and send on command for fallback
assert protocol.send_command_ack.call_args_list[3][0][1] == "on"
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1", ATTR_BRIGHTNESS: 128},
)
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1", ATTR_BRIGHTNESS: 128},
)
await hass.async_block_till_done()
assert protocol.send_command_ack.call_args_list[4][0][1] == "7"
hass.async_create_task(
hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: f"{DOMAIN}.dim_test", ATTR_BRIGHTNESS: 128},
)
await hass.services.async_call(
DOMAIN,
SERVICE_TURN_ON,
{ATTR_ENTITY_ID: f"{DOMAIN}.dim_test", ATTR_BRIGHTNESS: 128},
)
await hass.async_block_till_done()
@ -210,10 +200,8 @@ async def test_signal_repetitions(hass, monkeypatch):
)
# test if signal repetition is performed according to configuration
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
# wait for commands and repetitions to finish
@ -222,10 +210,8 @@ async def test_signal_repetitions(hass, monkeypatch):
assert protocol.send_command_ack.call_count == 2
# test if default apply to configured devices
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
# wait for commands and repetitions to finish
@ -239,10 +225,8 @@ async def test_signal_repetitions(hass, monkeypatch):
# make sure entity is created before setting state
await hass.async_block_till_done()
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.protocol_0_2"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.protocol_0_2"}
)
# wait for commands and repetitions to finish
@ -340,20 +324,16 @@ async def test_type_toggle(hass, monkeypatch):
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"
# test async_turn_off, must set state = 'on' ('off' + toggle)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "on"
# test async_turn_on, must set state = 'off' (yes, sounds crazy)
hass.async_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
await hass.async_block_till_done()

View file

@ -76,20 +76,16 @@ async 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_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{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_create_task(
hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.test").state == "on"