diff --git a/homeassistant/loader.py b/homeassistant/loader.py index 622c8524709..71f746e322b 100644 --- a/homeassistant/loader.py +++ b/homeassistant/loader.py @@ -109,6 +109,12 @@ CUSTOM_WARNING = ( "cause stability problems, be sure to disable it if you " "experience issues with Home Assistant" ) +IMPORT_EVENT_LOOP_WARNING = ( + "We found an integration %s which is configured to " + "to import its code in the event loop. This component might " + "cause stability problems, be sure to disable it if you " + "experience issues with Home Assistant" +) _UNDEF = object() # Internal; not helpers.typing.UNDEFINED due to circular dependency @@ -653,6 +659,9 @@ class Integration: None if is_virtual else set(os.listdir(file_path)), ) + if not integration.import_executor: + _LOGGER.warning(IMPORT_EVENT_LOOP_WARNING, integration.domain) + if integration.is_built_in: return integration @@ -821,9 +830,8 @@ class Integration: def import_executor(self) -> bool: """Import integration in the executor.""" # If the integration does not explicitly set import_executor, we default to - # True if it's a built-in integration and False if it's a custom integration. - # In the future, we want to default to True for all integrations. - return self.manifest.get("import_executor", self.is_built_in) + # True. + return self.manifest.get("import_executor", True) @cached_property def has_translations(self) -> bool: diff --git a/tests/test_loader.py b/tests/test_loader.py index 7828d197fc1..b51a9a846b8 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1098,7 +1098,7 @@ async def test_async_suggest_report_issue( def test_import_executor_default(hass: HomeAssistant) -> None: """Test that import_executor defaults.""" custom_comp = mock_integration(hass, MockModule("any_random"), built_in=False) - assert custom_comp.import_executor is False + assert custom_comp.import_executor is True built_in_comp = mock_integration(hass, MockModule("other_random"), built_in=True) assert built_in_comp.import_executor is True @@ -1675,3 +1675,13 @@ async def test_async_get_platforms_concurrent_loads( assert imports == [button_module_name] assert integration.get_platform_cached("button") is button_module_mock + + +async def test_integration_warnings( + hass: HomeAssistant, + enable_custom_integrations: None, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test integration warnings.""" + await loader.async_get_integration(hass, "test_package_loaded_loop") + assert "configured to to import its code in the event loop" in caplog.text diff --git a/tests/testing_config/custom_components/test_package_loaded_loop/__init__.py b/tests/testing_config/custom_components/test_package_loaded_loop/__init__.py new file mode 100644 index 00000000000..c4d88fd17d7 --- /dev/null +++ b/tests/testing_config/custom_components/test_package_loaded_loop/__init__.py @@ -0,0 +1,7 @@ +"""Provide a mock package component.""" +from .const import TEST # noqa: F401 + + +async def async_setup(hass, config): + """Mock a successful setup.""" + return True diff --git a/tests/testing_config/custom_components/test_package_loaded_loop/config_flow.py b/tests/testing_config/custom_components/test_package_loaded_loop/config_flow.py new file mode 100644 index 00000000000..9153b666828 --- /dev/null +++ b/tests/testing_config/custom_components/test_package_loaded_loop/config_flow.py @@ -0,0 +1,7 @@ +"""Config flow.""" + +from homeassistant.core import HomeAssistant + + +async def _async_has_devices(hass: HomeAssistant) -> bool: + return True diff --git a/tests/testing_config/custom_components/test_package_loaded_loop/const.py b/tests/testing_config/custom_components/test_package_loaded_loop/const.py new file mode 100644 index 00000000000..7e13e04cb47 --- /dev/null +++ b/tests/testing_config/custom_components/test_package_loaded_loop/const.py @@ -0,0 +1,2 @@ +"""Constants for test_package custom component.""" +TEST = 5 diff --git a/tests/testing_config/custom_components/test_package_loaded_loop/manifest.json b/tests/testing_config/custom_components/test_package_loaded_loop/manifest.json new file mode 100644 index 00000000000..e614d10b004 --- /dev/null +++ b/tests/testing_config/custom_components/test_package_loaded_loop/manifest.json @@ -0,0 +1,11 @@ +{ + "domain": "test_package_loaded_loop", + "name": "Test Package that loads in the loop", + "documentation": "http://test-package.io", + "requirements": [], + "dependencies": [], + "codeowners": [], + "config_flow": true, + "import_executor": false, + "version": "1.2.3" +}