mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Import custom components in the executor by default (#112177)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
parent
a2318c26c9
commit
afa69cca38
@ -109,6 +109,12 @@ CUSTOM_WARNING = (
|
|||||||
"cause stability problems, be sure to disable it if you "
|
"cause stability problems, be sure to disable it if you "
|
||||||
"experience issues with Home Assistant"
|
"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
|
_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)),
|
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:
|
if integration.is_built_in:
|
||||||
return integration
|
return integration
|
||||||
|
|
||||||
@ -821,9 +830,8 @@ class Integration:
|
|||||||
def import_executor(self) -> bool:
|
def import_executor(self) -> bool:
|
||||||
"""Import integration in the executor."""
|
"""Import integration in the executor."""
|
||||||
# If the integration does not explicitly set import_executor, we default to
|
# 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.
|
# True.
|
||||||
# In the future, we want to default to True for all integrations.
|
return self.manifest.get("import_executor", True)
|
||||||
return self.manifest.get("import_executor", self.is_built_in)
|
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def has_translations(self) -> bool:
|
def has_translations(self) -> bool:
|
||||||
|
@ -1098,7 +1098,7 @@ async def test_async_suggest_report_issue(
|
|||||||
def test_import_executor_default(hass: HomeAssistant) -> None:
|
def test_import_executor_default(hass: HomeAssistant) -> None:
|
||||||
"""Test that import_executor defaults."""
|
"""Test that import_executor defaults."""
|
||||||
custom_comp = mock_integration(hass, MockModule("any_random"), built_in=False)
|
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)
|
built_in_comp = mock_integration(hass, MockModule("other_random"), built_in=True)
|
||||||
assert built_in_comp.import_executor is 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 imports == [button_module_name]
|
||||||
assert integration.get_platform_cached("button") is button_module_mock
|
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
|
||||||
|
@ -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
|
@ -0,0 +1,7 @@
|
|||||||
|
"""Config flow."""
|
||||||
|
|
||||||
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
|
|
||||||
|
async def _async_has_devices(hass: HomeAssistant) -> bool:
|
||||||
|
return True
|
@ -0,0 +1,2 @@
|
|||||||
|
"""Constants for test_package custom component."""
|
||||||
|
TEST = 5
|
@ -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"
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user