Migrate remaining get_platform in check_config to async_get_platform (#112470)

These were very likely to be cached so they were low on the
list to migrate, but since they are called in the event loop
its best to be sure we do no blocking I/O
This commit is contained in:
J. Nick Koston 2024-03-05 18:47:41 -10:00 committed by GitHub
parent 0f69a0647c
commit 8fe80a4766
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -199,7 +199,7 @@ async def async_check_ha_config_file( # noqa: C901
# Check if the integration has a custom config validator
config_validator = None
try:
config_validator = integration.get_platform("config")
config_validator = await integration.async_get_platform("config")
except ImportError as err:
# Filter out import error of the config platform.
# If the config platform contains bad imports, make sure
@ -270,7 +270,7 @@ async def async_check_ha_config_file( # noqa: C901
p_integration = await async_get_integration_with_requirements(
hass, p_name
)
platform = p_integration.get_platform(domain)
platform = await p_integration.async_get_platform(domain)
except loader.IntegrationNotFound as ex:
# We get this error if an integration is not found. In recovery mode and
# safe mode, this currently happens for all custom integrations. Don't

View file

@ -338,7 +338,7 @@ async def test_config_platform_import_error(hass: HomeAssistant) -> None:
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: beer"}
with patch(
"homeassistant.loader.Integration.get_platform",
"homeassistant.loader.Integration.async_get_platform",
side_effect=ImportError("blablabla"),
), patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)
@ -358,7 +358,7 @@ async def test_platform_import_error(hass: HomeAssistant) -> None:
# Make sure they don't exist
files = {YAML_CONFIG_FILE: BASE_CONFIG + "light:\n platform: demo"}
with patch(
"homeassistant.loader.Integration.get_platform",
"homeassistant.loader.Integration.async_get_platform",
side_effect=[None, ImportError("blablabla")],
), patch("os.path.isfile", return_value=True), patch_yaml_files(files):
res = await async_check_ha_config_file(hass)