Fix import for new AWS aiobotocore lib (#64769)
* Fix import for new AWS aiobotocore lib * Fix patch for tests
This commit is contained in:
parent
27cb41a62c
commit
7884de3a31
3 changed files with 22 additions and 14 deletions
|
@ -3,7 +3,7 @@ import asyncio
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiobotocore
|
from aiobotocore.session import AioSession
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
@ -165,14 +165,14 @@ async def _validate_aws_credentials(hass, credential):
|
||||||
del aws_config[CONF_VALIDATE]
|
del aws_config[CONF_VALIDATE]
|
||||||
|
|
||||||
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
||||||
session = aiobotocore.session.AioSession(profile=profile)
|
session = AioSession(profile=profile)
|
||||||
del aws_config[CONF_PROFILE_NAME]
|
del aws_config[CONF_PROFILE_NAME]
|
||||||
if CONF_ACCESS_KEY_ID in aws_config:
|
if CONF_ACCESS_KEY_ID in aws_config:
|
||||||
del aws_config[CONF_ACCESS_KEY_ID]
|
del aws_config[CONF_ACCESS_KEY_ID]
|
||||||
if CONF_SECRET_ACCESS_KEY in aws_config:
|
if CONF_SECRET_ACCESS_KEY in aws_config:
|
||||||
del aws_config[CONF_SECRET_ACCESS_KEY]
|
del aws_config[CONF_SECRET_ACCESS_KEY]
|
||||||
else:
|
else:
|
||||||
session = aiobotocore.session.AioSession()
|
session = AioSession()
|
||||||
|
|
||||||
if credential[CONF_VALIDATE]:
|
if credential[CONF_VALIDATE]:
|
||||||
async with session.create_client("iam", **aws_config) as client:
|
async with session.create_client("iam", **aws_config) as client:
|
||||||
|
|
|
@ -4,7 +4,7 @@ import base64
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import aiobotocore
|
from aiobotocore.session import AioSession
|
||||||
|
|
||||||
from homeassistant.components.notify import (
|
from homeassistant.components.notify import (
|
||||||
ATTR_TARGET,
|
ATTR_TARGET,
|
||||||
|
@ -27,7 +27,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
async def get_available_regions(hass, service):
|
async def get_available_regions(hass, service):
|
||||||
"""Get available regions for a service."""
|
"""Get available regions for a service."""
|
||||||
session = aiobotocore.session.get_session()
|
session = AioSession()
|
||||||
return await session.get_available_regions(service)
|
return await session.get_available_regions(service)
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,10 +83,10 @@ async def async_get_service(hass, config, discovery_info=None):
|
||||||
|
|
||||||
if session is None:
|
if session is None:
|
||||||
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
if (profile := aws_config.get(CONF_PROFILE_NAME)) is not None:
|
||||||
session = aiobotocore.session.AioSession(profile=profile)
|
session = AioSession(profile=profile)
|
||||||
del aws_config[CONF_PROFILE_NAME]
|
del aws_config[CONF_PROFILE_NAME]
|
||||||
else:
|
else:
|
||||||
session = aiobotocore.session.AioSession()
|
session = AioSession()
|
||||||
|
|
||||||
aws_config[CONF_REGION] = region_name
|
aws_config[CONF_REGION] = region_name
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ class MockAioSession:
|
||||||
|
|
||||||
async def test_empty_config(hass):
|
async def test_empty_config(hass):
|
||||||
"""Test a default config will be create for empty config."""
|
"""Test a default config will be create for empty config."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
await async_setup_component(hass, "aws", {"aws": {}})
|
await async_setup_component(hass, "aws", {"aws": {}})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ async def test_empty_config(hass):
|
||||||
|
|
||||||
async def test_empty_credential(hass):
|
async def test_empty_credential(hass):
|
||||||
"""Test a default config will be create for empty credential section."""
|
"""Test a default config will be create for empty credential section."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
@ -84,7 +84,7 @@ async def test_empty_credential(hass):
|
||||||
|
|
||||||
async def test_profile_credential(hass):
|
async def test_profile_credential(hass):
|
||||||
"""Test credentials with profile name."""
|
"""Test credentials with profile name."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
@ -122,7 +122,7 @@ async def test_profile_credential(hass):
|
||||||
|
|
||||||
async def test_access_key_credential(hass):
|
async def test_access_key_credential(hass):
|
||||||
"""Test credentials with access key."""
|
"""Test credentials with access key."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
@ -167,7 +167,11 @@ async def test_access_key_credential(hass):
|
||||||
|
|
||||||
async def test_notify_credential(hass):
|
async def test_notify_credential(hass):
|
||||||
"""Test notify service can use access key directly."""
|
"""Test notify service can use access key directly."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch(
|
||||||
|
"homeassistant.components.aws.AioSession", new=MockAioSession
|
||||||
|
), async_patch(
|
||||||
|
"homeassistant.components.aws.notify.AioSession", new=MockAioSession
|
||||||
|
):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
@ -201,7 +205,11 @@ async def test_notify_credential(hass):
|
||||||
|
|
||||||
async def test_notify_credential_profile(hass):
|
async def test_notify_credential_profile(hass):
|
||||||
"""Test notify service can use profile directly."""
|
"""Test notify service can use profile directly."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch(
|
||||||
|
"homeassistant.components.aws.AioSession", new=MockAioSession
|
||||||
|
), async_patch(
|
||||||
|
"homeassistant.components.aws.notify.AioSession", new=MockAioSession
|
||||||
|
):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
@ -233,7 +241,7 @@ async def test_notify_credential_profile(hass):
|
||||||
|
|
||||||
async def test_credential_skip_validate(hass):
|
async def test_credential_skip_validate(hass):
|
||||||
"""Test credential can skip validate."""
|
"""Test credential can skip validate."""
|
||||||
with async_patch("aiobotocore.session.AioSession", new=MockAioSession):
|
with async_patch("homeassistant.components.aws.AioSession", new=MockAioSession):
|
||||||
await async_setup_component(
|
await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
"aws",
|
"aws",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue