diff --git a/homeassistant/components/aws_s3/__init__.py b/homeassistant/components/aws_s3/__init__.py index e28f22634f8f..b4aeab94a456 100644 --- a/homeassistant/components/aws_s3/__init__.py +++ b/homeassistant/components/aws_s3/__init__.py @@ -3,6 +3,7 @@ import logging from typing import cast +from aiobotocore.config import AioConfig from aiobotocore.session import AioSession from botocore.exceptions import ClientError, ConnectionError, ParamValidationError @@ -37,6 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: S3ConfigEntry) -> bool: endpoint_url=data.get(CONF_ENDPOINT_URL), aws_secret_access_key=data[CONF_SECRET_ACCESS_KEY], aws_access_key_id=data[CONF_ACCESS_KEY_ID], + config=AioConfig(warm_up_loader_caches=True), ).__aenter__() await client.head_bucket(Bucket=data[CONF_BUCKET]) except ClientError as err: diff --git a/homeassistant/components/aws_s3/config_flow.py b/homeassistant/components/aws_s3/config_flow.py index 36280a084709..4b01794771a1 100644 --- a/homeassistant/components/aws_s3/config_flow.py +++ b/homeassistant/components/aws_s3/config_flow.py @@ -3,6 +3,7 @@ from typing import Any, override from urllib.parse import urlparse +from aiobotocore.config import AioConfig from aiobotocore.session import AioSession from botocore.exceptions import ClientError, ConnectionError, ParamValidationError import voluptuous as vol @@ -77,6 +78,7 @@ class S3ConfigFlow(ConfigFlow, domain=DOMAIN): endpoint_url=user_input.get(CONF_ENDPOINT_URL), aws_secret_access_key=user_input[CONF_SECRET_ACCESS_KEY], aws_access_key_id=user_input[CONF_ACCESS_KEY_ID], + config=AioConfig(warm_up_loader_caches=True), ) as client: await client.head_bucket(Bucket=user_input[CONF_BUCKET]) except ClientError: diff --git a/tests/components/aws_s3/test_config_flow.py b/tests/components/aws_s3/test_config_flow.py index 90d2ce3311c6..17d1e86cc042 100644 --- a/tests/components/aws_s3/test_config_flow.py +++ b/tests/components/aws_s3/test_config_flow.py @@ -79,7 +79,17 @@ async def test_flow( expected_data: dict, ) -> None: """Test config flow with and without prefix, including prefix normalization.""" - result = await _async_start_flow(hass, user_input) + create_client = AsyncMock(name="create_client") + create_client.__aenter__.return_value.head_bucket.return_value = {} + + with patch( + "homeassistant.components.aws_s3.config_flow.AioSession.create_client", + return_value=create_client, + ) as patched_create_client: + result = await _async_start_flow(hass, user_input) + + assert patched_create_client.call_args.kwargs["config"].warm_up_loader_caches + assert result["type"] is FlowResultType.CREATE_ENTRY assert result["title"] == expected_title assert result["data"] == expected_data diff --git a/tests/components/aws_s3/test_init.py b/tests/components/aws_s3/test_init.py index ee247bfce1de..04afa23f388c 100644 --- a/tests/components/aws_s3/test_init.py +++ b/tests/components/aws_s3/test_init.py @@ -73,3 +73,23 @@ async def test_setup_entry_head_bucket_error( ) await setup_integration(hass, mock_config_entry) assert mock_config_entry.state is ConfigEntryState.SETUP_ERROR + + +async def test_setup_entry_warms_loader_caches( + hass: HomeAssistant, + mock_config_entry: MockConfigEntry, +) -> None: + """Test that create_client passes warm_up_loader_caches config.""" + with patch( + "homeassistant.components.aws_s3.AioSession.create_client" + ) as create_client: + client_ctx = AsyncMock() + client = AsyncMock() + client_ctx.__aenter__.return_value = client + create_client.return_value = client_ctx + + await setup_integration(hass, mock_config_entry) + + create_client.assert_called_once() + _, kwargs = create_client.call_args + assert kwargs["config"].warm_up_loader_caches is True