mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix scene integration doing blocking I/O in the event loop to import platforms (#113391)
This commit is contained in:
parent
09934d44c4
commit
052d7d1e19
@ -35,6 +35,11 @@ from homeassistant.helpers.service import (
|
||||
from homeassistant.helpers.template import async_load_custom_templates
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
# The scene integration will do a late import of scene
|
||||
# so we want to make sure its loaded with the component
|
||||
# so its already in memory when its imported so the import
|
||||
# does not do blocking I/O in the event loop.
|
||||
from . import scene as scene_pre_import # noqa: F401
|
||||
from .const import (
|
||||
DATA_EXPOSED_ENTITIES,
|
||||
DATA_STOP_HANDLER,
|
||||
|
@ -32,15 +32,13 @@ def _hass_domain_validator(config: dict[str, Any]) -> dict[str, Any]:
|
||||
|
||||
def _platform_validator(config: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Validate it is a valid platform."""
|
||||
platform_name = config[CONF_PLATFORM]
|
||||
try:
|
||||
platform = importlib.import_module(f".{config[CONF_PLATFORM]}", __name__)
|
||||
platform = importlib.import_module(
|
||||
f"homeassistant.components.{platform_name}.scene"
|
||||
)
|
||||
except ImportError:
|
||||
try:
|
||||
platform = importlib.import_module(
|
||||
f"homeassistant.components.{config[CONF_PLATFORM]}.scene"
|
||||
)
|
||||
except ImportError:
|
||||
raise vol.Invalid("Invalid platform specified") from None
|
||||
raise vol.Invalid("Invalid platform specified") from None
|
||||
|
||||
if not hasattr(platform, "PLATFORM_SCHEMA"):
|
||||
return config
|
||||
|
@ -262,3 +262,15 @@ async def turn_off_lights(hass, entity_ids):
|
||||
blocking=True,
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
|
||||
async def test_invalid_platform(
|
||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||
) -> None:
|
||||
"""Test invalid platform."""
|
||||
await async_setup_component(
|
||||
hass, scene.DOMAIN, {scene.DOMAIN: {"platform": "does_not_exist"}}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert "Invalid platform specified" in caplog.text
|
||||
assert "does_not_exist" in caplog.text
|
||||
|
Loading…
x
Reference in New Issue
Block a user