mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix telegram_bot doing blocking I/O in the event loop to import platforms (#113383)
This commit is contained in:
parent
4341b21a61
commit
c122e32d20
@ -3,7 +3,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import importlib
|
|
||||||
import io
|
import io
|
||||||
from ipaddress import ip_network
|
from ipaddress import ip_network
|
||||||
import logging
|
import logging
|
||||||
@ -41,6 +40,7 @@ from homeassistant.core import HomeAssistant, ServiceCall
|
|||||||
from homeassistant.exceptions import TemplateError
|
from homeassistant.exceptions import TemplateError
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
from homeassistant.loader import async_get_loaded_integration
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -355,15 +355,21 @@ async def load_data(
|
|||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
"""Set up the Telegram bot component."""
|
"""Set up the Telegram bot component."""
|
||||||
if not config[DOMAIN]:
|
domain_config: list[dict[str, Any]] = config[DOMAIN]
|
||||||
|
|
||||||
|
if not domain_config:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for p_config in config[DOMAIN]:
|
platforms = await async_get_loaded_integration(hass, DOMAIN).async_get_platforms(
|
||||||
|
{p_config[CONF_PLATFORM] for p_config in domain_config}
|
||||||
|
)
|
||||||
|
|
||||||
|
for p_config in domain_config:
|
||||||
# Each platform config gets its own bot
|
# Each platform config gets its own bot
|
||||||
bot = initialize_bot(p_config)
|
bot = initialize_bot(p_config)
|
||||||
p_type = p_config.get(CONF_PLATFORM)
|
p_type: str = p_config[CONF_PLATFORM]
|
||||||
|
|
||||||
platform = importlib.import_module(f".{p_config[CONF_PLATFORM]}", __name__)
|
platform = platforms[p_type]
|
||||||
|
|
||||||
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
|
_LOGGER.info("Setting up %s.%s", DOMAIN, p_type)
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user