mirror of
https://github.com/home-assistant/core.git
synced 2025-04-27 02:37:50 +00:00
Switch config to use async_get_component/async_get_platform (#112071)
This commit is contained in:
parent
08897137ff
commit
3808e8b0bc
@ -1418,7 +1418,7 @@ async def async_process_component_config( # noqa: C901
|
|||||||
config_exceptions: list[ConfigExceptionInfo] = []
|
config_exceptions: list[ConfigExceptionInfo] = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
component = integration.get_component()
|
component = await integration.async_get_component()
|
||||||
except LOAD_EXCEPTIONS as exc:
|
except LOAD_EXCEPTIONS as exc:
|
||||||
exc_info = ConfigExceptionInfo(
|
exc_info = ConfigExceptionInfo(
|
||||||
exc,
|
exc,
|
||||||
@ -1433,7 +1433,7 @@ async def async_process_component_config( # noqa: C901
|
|||||||
# Check if the integration has a custom config validator
|
# Check if the integration has a custom config validator
|
||||||
config_validator = None
|
config_validator = None
|
||||||
try:
|
try:
|
||||||
config_validator = integration.get_platform("config")
|
config_validator = await integration.async_get_platform("config")
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
# Filter out import error of the config platform.
|
# Filter out import error of the config platform.
|
||||||
# If the config platform contains bad imports, make sure
|
# If the config platform contains bad imports, make sure
|
||||||
@ -1557,7 +1557,7 @@ async def async_process_component_config( # noqa: C901
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
platform = p_integration.get_platform(domain)
|
platform = await p_integration.async_get_platform(domain)
|
||||||
except LOAD_EXCEPTIONS as exc:
|
except LOAD_EXCEPTIONS as exc:
|
||||||
exc_info = ConfigExceptionInfo(
|
exc_info = ConfigExceptionInfo(
|
||||||
exc,
|
exc,
|
||||||
|
@ -1430,7 +1430,8 @@ async def test_component_config_exceptions(
|
|||||||
# Config validator
|
# Config validator
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(
|
async_get_component=AsyncMock(),
|
||||||
|
async_get_platform=AsyncMock(
|
||||||
return_value=Mock(
|
return_value=Mock(
|
||||||
async_validate_config=AsyncMock(side_effect=ValueError("broken"))
|
async_validate_config=AsyncMock(side_effect=ValueError("broken"))
|
||||||
)
|
)
|
||||||
@ -1455,14 +1456,14 @@ async def test_component_config_exceptions(
|
|||||||
|
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(
|
async_get_platform=AsyncMock(
|
||||||
return_value=Mock(
|
return_value=Mock(
|
||||||
async_validate_config=AsyncMock(
|
async_validate_config=AsyncMock(
|
||||||
side_effect=HomeAssistantError("broken")
|
side_effect=HomeAssistantError("broken")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
get_component=Mock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
async_get_component=AsyncMock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
||||||
)
|
)
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
assert (
|
assert (
|
||||||
@ -1482,8 +1483,8 @@ async def test_component_config_exceptions(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(return_value=None),
|
async_get_platform=AsyncMock(return_value=None),
|
||||||
get_component=Mock(
|
async_get_component=AsyncMock(
|
||||||
return_value=Mock(CONFIG_SCHEMA=Mock(side_effect=ValueError("broken")))
|
return_value=Mock(CONFIG_SCHEMA=Mock(side_effect=ValueError("broken")))
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -1511,8 +1512,8 @@ async def test_component_config_exceptions(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(return_value=None),
|
async_get_platform=AsyncMock(return_value=None),
|
||||||
get_component=Mock(
|
async_get_component=AsyncMock(
|
||||||
return_value=Mock(
|
return_value=Mock(
|
||||||
spec=["PLATFORM_SCHEMA_BASE"],
|
spec=["PLATFORM_SCHEMA_BASE"],
|
||||||
PLATFORM_SCHEMA_BASE=Mock(side_effect=ValueError("broken")),
|
PLATFORM_SCHEMA_BASE=Mock(side_effect=ValueError("broken")),
|
||||||
@ -1551,13 +1552,13 @@ async def test_component_config_exceptions(
|
|||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(return_value=None),
|
async_get_platform=AsyncMock(return_value=None),
|
||||||
get_component=Mock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
async_get_component=AsyncMock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.config.async_get_integration_with_requirements",
|
"homeassistant.config.async_get_integration_with_requirements",
|
||||||
return_value=Mock( # integration that owns platform
|
return_value=Mock( # integration that owns platform
|
||||||
get_platform=Mock(
|
async_get_platform=AsyncMock(
|
||||||
return_value=Mock( # platform
|
return_value=Mock( # platform
|
||||||
PLATFORM_SCHEMA=Mock(side_effect=ValueError("broken"))
|
PLATFORM_SCHEMA=Mock(side_effect=ValueError("broken"))
|
||||||
)
|
)
|
||||||
@ -1640,12 +1641,12 @@ async def test_component_config_exceptions(
|
|||||||
"for test_domain component with PLATFORM_SCHEMA"
|
"for test_domain component with PLATFORM_SCHEMA"
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
|
|
||||||
# get_platform("domain") raising on ImportError
|
# async_get_platform("domain") raising on ImportError
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(return_value=None),
|
async_get_platform=AsyncMock(return_value=None),
|
||||||
get_component=Mock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
async_get_component=AsyncMock(return_value=Mock(spec=["PLATFORM_SCHEMA_BASE"])),
|
||||||
)
|
)
|
||||||
import_error = ImportError(
|
import_error = ImportError(
|
||||||
("ModuleNotFoundError: No module named 'not_installed_something'"),
|
("ModuleNotFoundError: No module named 'not_installed_something'"),
|
||||||
@ -1654,7 +1655,7 @@ async def test_component_config_exceptions(
|
|||||||
with patch(
|
with patch(
|
||||||
"homeassistant.config.async_get_integration_with_requirements",
|
"homeassistant.config.async_get_integration_with_requirements",
|
||||||
return_value=Mock( # integration that owns platform
|
return_value=Mock( # integration that owns platform
|
||||||
get_platform=Mock(side_effect=import_error)
|
async_get_platform=AsyncMock(side_effect=import_error)
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
assert await config_util.async_process_component_and_handle_errors(
|
assert await config_util.async_process_component_and_handle_errors(
|
||||||
@ -1688,12 +1689,13 @@ async def test_component_config_exceptions(
|
|||||||
"No module named 'not_installed_something'"
|
"No module named 'not_installed_something'"
|
||||||
) in str(ex.value)
|
) in str(ex.value)
|
||||||
|
|
||||||
# get_platform("config") raising
|
# async_get_platform("config") raising
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
pkg_path="homeassistant.components.test_domain",
|
pkg_path="homeassistant.components.test_domain",
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_platform=Mock(
|
async_get_component=AsyncMock(),
|
||||||
|
async_get_platform=AsyncMock(
|
||||||
side_effect=ImportError(
|
side_effect=ImportError(
|
||||||
("ModuleNotFoundError: No module named 'not_installed_something'"),
|
("ModuleNotFoundError: No module named 'not_installed_something'"),
|
||||||
name="not_installed_something",
|
name="not_installed_something",
|
||||||
@ -1729,12 +1731,12 @@ async def test_component_config_exceptions(
|
|||||||
"No module named 'not_installed_something'" in str(ex.value)
|
"No module named 'not_installed_something'" in str(ex.value)
|
||||||
)
|
)
|
||||||
|
|
||||||
# get_component raising
|
# async_get_component raising
|
||||||
caplog.clear()
|
caplog.clear()
|
||||||
test_integration = Mock(
|
test_integration = Mock(
|
||||||
pkg_path="homeassistant.components.test_domain",
|
pkg_path="homeassistant.components.test_domain",
|
||||||
domain="test_domain",
|
domain="test_domain",
|
||||||
get_component=Mock(
|
async_get_component=AsyncMock(
|
||||||
side_effect=FileNotFoundError("No such file or directory: b'liblibc.a'")
|
side_effect=FileNotFoundError("No such file or directory: b'liblibc.a'")
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user