From 99d2d72d13719730ccb65a00871ad80cb1ed10bb Mon Sep 17 00:00:00 2001 From: javicalle <31999997+javicalle@users.noreply.github.com> Date: Sun, 21 Mar 2021 03:27:24 +0100 Subject: [PATCH] Update RFLink tests (#48149) --- tests/components/rflink/test_cover.py | 152 +++++++++---------------- tests/components/rflink/test_init.py | 44 +++---- tests/components/rflink/test_light.py | 68 ++++------- tests/components/rflink/test_switch.py | 12 +- 4 files changed, 102 insertions(+), 174 deletions(-) diff --git a/tests/components/rflink/test_cover.py b/tests/components/rflink/test_cover.py index fd3f5b84314..1dac064d778 100644 --- a/tests/components/rflink/test_cover.py +++ b/tests/components/rflink/test_cover.py @@ -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() diff --git a/tests/components/rflink/test_init.py b/tests/components/rflink/test_init.py index 233170d8cd2..f93c9703d30 100644 --- a/tests/components/rflink/test_init.py +++ b/tests/components/rflink/test_init.py @@ -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" diff --git a/tests/components/rflink/test_light.py b/tests/components/rflink/test_light.py index f3ea5e30375..79fa752e54c 100644 --- a/tests/components/rflink/test_light.py +++ b/tests/components/rflink/test_light.py @@ -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() diff --git a/tests/components/rflink/test_switch.py b/tests/components/rflink/test_switch.py index d696e8933be..ef6bac55f21 100644 --- a/tests/components/rflink/test_switch.py +++ b/tests/components/rflink/test_switch.py @@ -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"