From 8fe80a4766aa7cc55ab911bfd78f85671fac4c3c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 5 Mar 2024 18:47:41 -1000 Subject: [PATCH] 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 --- homeassistant/helpers/check_config.py | 4 ++-- tests/helpers/test_check_config.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index b362d68ad55..0de11303cf9 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -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 diff --git a/tests/helpers/test_check_config.py b/tests/helpers/test_check_config.py index edf1066f744..a7c5fe36cff 100644 --- a/tests/helpers/test_check_config.py +++ b/tests/helpers/test_check_config.py @@ -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)