From d34753473d6c6712ad3990ea9c4f8ba35df7ee84 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 27 Nov 2020 16:12:39 +0100 Subject: [PATCH] Use run_job for service helper (#43696) --- homeassistant/helpers/service.py | 4 ++-- tests/components/input_boolean/test_init.py | 18 +++++++----------- tests/components/input_datetime/test_init.py | 3 --- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index e6c805e9a35..c3700581b40 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -531,7 +531,7 @@ async def _handle_entity_call( else: result = hass.async_run_job(func, entity, data) - # Guard because callback functions do not return a task when passed to async_add_job. + # Guard because callback functions do not return a task when passed to async_run_job. if result is not None: await result @@ -564,7 +564,7 @@ def async_register_admin_service( if not user.is_admin: raise Unauthorized(context=call.context) - result = hass.async_add_job(service_func, call) + result = hass.async_run_job(service_func, call) if result is not None: await result diff --git a/tests/components/input_boolean/test_init.py b/tests/components/input_boolean/test_init.py index 1e3150e687a..9911ced28dd 100644 --- a/tests/components/input_boolean/test_init.py +++ b/tests/components/input_boolean/test_init.py @@ -63,23 +63,21 @@ async def test_methods(hass): assert not is_on(hass, entity_id) - await hass.services.async_call(DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}) - - await hass.async_block_till_done() + await hass.services.async_call( + DOMAIN, SERVICE_TURN_ON, {ATTR_ENTITY_ID: entity_id}, blocking=True + ) assert is_on(hass, entity_id) await hass.services.async_call( - DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id} + DOMAIN, SERVICE_TURN_OFF, {ATTR_ENTITY_ID: entity_id}, blocking=True ) - await hass.async_block_till_done() - assert not is_on(hass, entity_id) - await hass.services.async_call(DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id}) - - await hass.async_block_till_done() + await hass.services.async_call( + DOMAIN, SERVICE_TOGGLE, {ATTR_ENTITY_ID: entity_id}, blocking=True + ) assert is_on(hass, entity_id) @@ -246,7 +244,6 @@ async def test_reload(hass, hass_admin_user): blocking=True, context=Context(user_id=hass_admin_user.id), ) - await hass.async_block_till_done() assert count_start + 2 == len(hass.states.async_entity_ids()) @@ -349,6 +346,5 @@ async def test_setup_no_config(hass, hass_admin_user): blocking=True, context=Context(user_id=hass_admin_user.id), ) - await hass.async_block_till_done() assert count_start == len(hass.states.async_entity_ids()) diff --git a/tests/components/input_datetime/test_init.py b/tests/components/input_datetime/test_init.py index 53914a83ba2..d40a88e3f43 100644 --- a/tests/components/input_datetime/test_init.py +++ b/tests/components/input_datetime/test_init.py @@ -276,7 +276,6 @@ async def test_set_invalid_2(hass): {"entity_id": entity_id, "time": time_portion, "datetime": dt_obj}, blocking=True, ) - await hass.async_block_till_done() state = hass.states.get(entity_id) assert state.state == initial @@ -467,7 +466,6 @@ async def test_reload(hass, hass_admin_user, hass_read_only_user): blocking=True, context=Context(user_id=hass_admin_user.id), ) - await hass.async_block_till_done() assert count_start + 2 == len(hass.states.async_entity_ids()) @@ -643,7 +641,6 @@ async def test_setup_no_config(hass, hass_admin_user): blocking=True, context=Context(user_id=hass_admin_user.id), ) - await hass.async_block_till_done() assert count_start == len(hass.states.async_entity_ids())