diff --git a/tests/components/alert/test_init.py b/tests/components/alert/test_init.py index 8dfbb437646..7c4030b56da 100644 --- a/tests/components/alert/test_init.py +++ b/tests/components/alert/test_init.py @@ -342,6 +342,6 @@ async def test_done_message_state_tracker_reset_on_cancel(hass: HomeAssistant) - entity._cancel = lambda *args: None assert entity._send_done_message is False entity._send_done_message = True - hass.async_add_job(entity.end_alerting) + await entity.end_alerting() await hass.async_block_till_done() assert entity._send_done_message is False diff --git a/tests/components/counter/common.py b/tests/components/counter/common.py index 3cd7dd3c300..72d183a7b0f 100644 --- a/tests/components/counter/common.py +++ b/tests/components/counter/common.py @@ -19,7 +19,7 @@ from homeassistant.loader import bind_hass @bind_hass def async_increment(hass, entity_id): """Increment a counter.""" - hass.async_add_job( + hass.create_task( hass.services.async_call(DOMAIN, SERVICE_INCREMENT, {ATTR_ENTITY_ID: entity_id}) ) @@ -28,7 +28,7 @@ def async_increment(hass, entity_id): @bind_hass def async_decrement(hass, entity_id): """Decrement a counter.""" - hass.async_add_job( + hass.create_task( hass.services.async_call(DOMAIN, SERVICE_DECREMENT, {ATTR_ENTITY_ID: entity_id}) ) @@ -37,6 +37,6 @@ def async_decrement(hass, entity_id): @bind_hass def async_reset(hass, entity_id): """Reset a counter.""" - hass.async_add_job( + hass.create_task( hass.services.async_call(DOMAIN, SERVICE_RESET, {ATTR_ENTITY_ID: entity_id}) ) diff --git a/tests/components/device_tracker/common.py b/tests/components/device_tracker/common.py index 499c3ac6cda..6e2c7b253c3 100644 --- a/tests/components/device_tracker/common.py +++ b/tests/components/device_tracker/common.py @@ -50,4 +50,4 @@ def async_see( } if attributes: data[ATTR_ATTRIBUTES] = attributes - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SEE, data)) + hass.create_task(hass.services.async_call(DOMAIN, SERVICE_SEE, data)) diff --git a/tests/components/ffmpeg/test_binary_sensor.py b/tests/components/ffmpeg/test_binary_sensor.py index 72d6fee5e7f..8b1a5115f86 100644 --- a/tests/components/ffmpeg/test_binary_sensor.py +++ b/tests/components/ffmpeg/test_binary_sensor.py @@ -65,7 +65,7 @@ async def test_noise_setup_component_start_callback(mock_ffmpeg, hass: HomeAssis entity = hass.states.get("binary_sensor.ffmpeg_noise") assert entity.state == "off" - hass.async_add_job(mock_ffmpeg.call_args[0][1], True) + mock_ffmpeg.call_args[0][1](True) await hass.async_block_till_done() entity = hass.states.get("binary_sensor.ffmpeg_noise") @@ -121,7 +121,7 @@ async def test_motion_setup_component_start_callback(mock_ffmpeg, hass: HomeAssi entity = hass.states.get("binary_sensor.ffmpeg_motion") assert entity.state == "off" - hass.async_add_job(mock_ffmpeg.call_args[0][1], True) + mock_ffmpeg.call_args[0][1](True) await hass.async_block_till_done() entity = hass.states.get("binary_sensor.ffmpeg_motion") diff --git a/tests/components/ffmpeg/test_init.py b/tests/components/ffmpeg/test_init.py index 5ead1bcf942..e945a26e05b 100644 --- a/tests/components/ffmpeg/test_init.py +++ b/tests/components/ffmpeg/test_init.py @@ -27,7 +27,7 @@ def async_start(hass, entity_id=None): This is a legacy helper method. Do not use it for new tests. """ data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_START, data)) + hass.create_task(hass.services.async_call(DOMAIN, SERVICE_START, data)) @callback @@ -37,7 +37,7 @@ def async_stop(hass, entity_id=None): This is a legacy helper method. Do not use it for new tests. """ data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_STOP, data)) + hass.create_task(hass.services.async_call(DOMAIN, SERVICE_STOP, data)) @callback @@ -47,7 +47,7 @@ def async_restart(hass, entity_id=None): This is a legacy helper method. Do not use it for new tests. """ data = {ATTR_ENTITY_ID: entity_id} if entity_id else {} - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RESTART, data)) + hass.create_task(hass.services.async_call(DOMAIN, SERVICE_RESTART, data)) class MockFFmpegDev(ffmpeg.FFmpegBase): diff --git a/tests/components/group/common.py b/tests/components/group/common.py index d24deb2f34f..395fc990930 100644 --- a/tests/components/group/common.py +++ b/tests/components/group/common.py @@ -27,7 +27,7 @@ def reload(hass): @bind_hass def async_reload(hass): """Reload the automation from config.""" - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_RELOAD)) + hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_RELOAD)) @bind_hass @@ -74,7 +74,7 @@ def async_set_group( if value is not None } - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SET, data)) + hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SET, data)) @callback @@ -82,4 +82,4 @@ def async_set_group( def async_remove(hass, object_id): """Remove a user group.""" data = {ATTR_OBJECT_ID: object_id} - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data)) + hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_REMOVE, data)) diff --git a/tests/components/group/test_init.py b/tests/components/group/test_init.py index c609c705f21..66b744cddc9 100644 --- a/tests/components/group/test_init.py +++ b/tests/components/group/test_init.py @@ -1232,6 +1232,8 @@ async def test_group_vacuum_on(hass: HomeAssistant) -> None: async def test_device_tracker_not_home(hass: HomeAssistant) -> None: """Test group of device_tracker not_home.""" + await async_setup_component(hass, "device_tracker", {}) + await hass.async_block_till_done() hass.states.async_set("device_tracker.one", "not_home") hass.states.async_set("device_tracker.two", "not_home") hass.states.async_set("device_tracker.three", "not_home") diff --git a/tests/components/homematicip_cloud/test_hap.py b/tests/components/homematicip_cloud/test_hap.py index de47360770f..72bdb5cc0fc 100644 --- a/tests/components/homematicip_cloud/test_hap.py +++ b/tests/components/homematicip_cloud/test_hap.py @@ -101,7 +101,7 @@ async def test_hap_setup_connection_error() -> None: ): assert not await hap.async_setup() - assert not hass.async_add_job.mock_calls + assert not hass.async_add_hass_job.mock_calls assert not hass.config_entries.flow.async_init.mock_calls diff --git a/tests/components/image_processing/common.py b/tests/components/image_processing/common.py index d0354696e8a..4b3a008c6cd 100644 --- a/tests/components/image_processing/common.py +++ b/tests/components/image_processing/common.py @@ -21,4 +21,4 @@ def scan(hass, entity_id=ENTITY_MATCH_ALL): def async_scan(hass, entity_id=ENTITY_MATCH_ALL): """Force process of all cameras or given entity.""" data = {ATTR_ENTITY_ID: entity_id} if entity_id else None - hass.async_add_job(hass.services.async_call(DOMAIN, SERVICE_SCAN, data)) + hass.async_create_task(hass.services.async_call(DOMAIN, SERVICE_SCAN, data)) diff --git a/tests/components/mqtt/test_util.py b/tests/components/mqtt/test_util.py index 0b8d7002319..b07dfc1f642 100644 --- a/tests/components/mqtt/test_util.py +++ b/tests/components/mqtt/test_util.py @@ -159,10 +159,8 @@ async def test_waiting_for_client_not_loaded( unsubs.append(await mqtt.async_subscribe(hass, "test_topic", lambda msg: None)) # Simulate some integration waiting for the client to become available - hass.async_add_job(_async_just_in_time_subscribe) - hass.async_add_job(_async_just_in_time_subscribe) - hass.async_add_job(_async_just_in_time_subscribe) - hass.async_add_job(_async_just_in_time_subscribe) + for _ in range(4): + hass.async_create_task(_async_just_in_time_subscribe()) assert entry.state == ConfigEntryState.NOT_LOADED assert await hass.config_entries.async_setup(entry.entry_id) @@ -210,7 +208,7 @@ async def test_waiting_for_client_entry_fails( async def _async_just_in_time_subscribe() -> Callable[[], None]: assert not await mqtt.async_wait_for_mqtt_client(hass) - hass.async_add_job(_async_just_in_time_subscribe) + hass.async_create_task(_async_just_in_time_subscribe()) assert entry.state == ConfigEntryState.NOT_LOADED with patch( "homeassistant.components.mqtt.async_setup_entry", @@ -238,7 +236,7 @@ async def test_waiting_for_client_setup_fails( async def _async_just_in_time_subscribe() -> Callable[[], None]: assert not await mqtt.async_wait_for_mqtt_client(hass) - hass.async_add_job(_async_just_in_time_subscribe) + hass.async_create_task(_async_just_in_time_subscribe()) assert entry.state == ConfigEntryState.NOT_LOADED # Simulate MQTT setup fails before the client would become available diff --git a/tests/components/python_script/test_init.py b/tests/components/python_script/test_init.py index 81a98f5828a..ced279b2f9a 100644 --- a/tests/components/python_script/test_init.py +++ b/tests/components/python_script/test_init.py @@ -250,7 +250,7 @@ for index, value in enumerate(["earth", "mars"]): hass.states.set('hello.{}'.format(index), value) """ - hass.async_add_job(execute, hass, "test.py", source, {}) + await hass.async_add_executor_job(execute, hass, "test.py", source, {}) await hass.async_block_till_done() assert hass.states.is_state("hello.0", "earth")