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,21 +89,17 @@ 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(
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(
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
assert protocol.send_command_ack.call_args_list[1][0][1] == "UP"
@ -162,11 +158,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
# wait for commands and repetitions to finish
await hass.async_block_till_done()
@ -174,11 +168,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
# wait for commands and repetitions to finish
await hass.async_block_till_done()
@ -202,16 +194,12 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
hass.async_create_task(
hass.services.async_call(
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
await hass.async_block_till_done()
@ -234,17 +222,13 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
hass.async_create_task(
hass.services.async_call(
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
await hass.async_block_till_done()
@ -606,13 +590,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
)
await hass.async_block_till_done()
@ -623,13 +605,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_standard"},
)
)
await hass.async_block_till_done()
@ -640,11 +620,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
)
await hass.async_block_till_done()
@ -655,11 +633,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_none"}
)
)
await hass.async_block_till_done()
@ -670,13 +646,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
)
await hass.async_block_till_done()
@ -687,13 +661,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.nonkaku_type_inverted"},
)
)
await hass.async_block_till_done()
@ -704,13 +676,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
)
await hass.async_block_till_done()
@ -721,13 +691,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_standard"},
)
)
await hass.async_block_till_done()
@ -738,11 +706,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_CLOSE_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
)
await hass.async_block_till_done()
@ -753,11 +719,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_none"}
)
)
await hass.async_block_till_done()
@ -768,13 +732,11 @@ 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(
await hass.services.async_call(
DOMAIN,
SERVICE_CLOSE_COVER,
{ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_type_inverted"},
)
)
await hass.async_block_till_done()
@ -785,13 +747,11 @@ 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(
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,11 +107,9 @@ 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(
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"
assert protocol.send_command.call_args_list[0][0][1] == "off"
@ -133,11 +131,9 @@ 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(
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"
assert protocol.send_command.call_args_list[0][0][1] == "STOP"
@ -151,13 +147,11 @@ 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(
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"
assert protocol.send_command_ack.call_args_list[0][0][1] == "on"
@ -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(
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(
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,21 +96,17 @@ 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(
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(
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"
assert protocol.send_command_ack.call_args_list[1][0][1] == "on"
@ -118,11 +114,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.newkaku_0_1"}
)
)
await hass.async_block_till_done()
# dimmable should send highest dim level when turning on
@ -131,24 +125,20 @@ 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(
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(
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()
assert protocol.send_command_ack.call_args_list[5][0][1] == "7"
@ -210,11 +200,9 @@ async def test_signal_repetitions(hass, monkeypatch):
)
# test if signal repetition is performed according to configuration
hass.async_create_task(
hass.services.async_call(
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test"}
)
)
# wait for commands and repetitions to finish
await hass.async_block_till_done()
@ -222,11 +210,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.test1"}
)
)
# wait for commands and repetitions to finish
await hass.async_block_till_done()
@ -239,11 +225,9 @@ 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(
await hass.services.async_call(
DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: f"{DOMAIN}.protocol_0_2"}
)
)
# wait for commands and repetitions to finish
await hass.async_block_till_done()
@ -340,21 +324,17 @@ 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(
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(
await hass.services.async_call(
DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: f"{DOMAIN}.toggle_test"}
)
)
await hass.async_block_till_done()
assert hass.states.get(f"{DOMAIN}.toggle_test").state == "off"

View file

@ -76,21 +76,17 @@ 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(
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(
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"
assert protocol.send_command_ack.call_args_list[1][0][1] == "on"