Speed up importing mqtt platforms (#112682)

Use async_forward_entry_setups so platforms can be loaded in a single
executor job instead of many:

Currently they all have to create a new job because it did not use
async_forward_entry_setups

```
2024-03-08 08:29:29.819 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[light] loop=[] took 12.12s
2024-03-08 08:29:29.822 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[number] loop=[] took 12.12s
2024-03-08 08:29:29.826 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[scene] loop=[] took 12.13s
2024-03-08 08:29:29.829 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[select] loop=[] took 12.13s
2024-03-08 08:29:29.833 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[sensor] loop=[] took 12.14s
2024-03-08 08:29:30.882 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[update] loop=[] took 13.18s
2024-03-08 08:29:30.948 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[button] loop=[] took 13.18s
2024-03-08 08:29:30.949 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[climate] loop=[] took 13.19s
2024-03-08 08:29:31.012 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[fan] loop=[] took 13.25s
2024-03-08 08:29:31.019 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[humidifier] loop=[] took 13.25s
2024-03-08 08:29:31.024 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[image] loop=[] took 13.26s
2024-03-08 08:29:31.034 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[lock] loop=[] took 13.27s
2024-03-08 08:29:31.045 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[vacuum] loop=[] took 13.28s
2024-03-08 08:29:31.050 DEBUG (MainThread) [homeassistant.loader] Importing platforms for mqtt executor=[valve] loop=[] took 13.28s
```
This commit is contained in:
J. Nick Koston 2024-03-07 23:30:31 -10:00 committed by GitHub
parent d2effd8693
commit 7dcf275966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -40,6 +40,7 @@ from homeassistant.helpers.reload import async_integration_yaml_config
from homeassistant.helpers.service import async_register_admin_service
from homeassistant.helpers.typing import ConfigType
from homeassistant.loader import async_get_integration
from homeassistant.util.async_ import create_eager_task
# Loading the config flow file will register the flow
from . import debug_info, discovery
@ -449,14 +450,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
# Forward the entry setup to the MQTT platforms
await asyncio.gather(
*(
[
device_automation.async_setup_entry(hass, config_entry),
tag.async_setup_entry(hass, config_entry),
]
+ [
hass.config_entries.async_forward_entry_setup(entry, component)
for component in PLATFORMS
]
create_eager_task(
device_automation.async_setup_entry(hass, config_entry)
),
create_eager_task(tag.async_setup_entry(hass, config_entry)),
create_eager_task(
hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
),
)
)
# Setup discovery