Fix blocking I/O to import modules in mysensors (#116516)

This commit is contained in:
J. Nick Koston 2024-05-01 08:22:50 -05:00 committed by GitHub
parent c46be022c8
commit 61a7bc7aab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,7 +10,7 @@ import socket
import sys
from typing import Any
from mysensors import BaseAsyncGateway, Message, Sensor, mysensors
from mysensors import BaseAsyncGateway, Message, Sensor, get_const, mysensors
import voluptuous as vol
from homeassistant.components.mqtt import (
@ -24,6 +24,7 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_DEVICE, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import Event, HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.setup import SetupPhases, async_pause_setup
from homeassistant.util.unit_system import METRIC_SYSTEM
from .const import (
@ -162,6 +163,12 @@ async def _get_gateway(
) -> BaseAsyncGateway | None:
"""Return gateway after setup of the gateway."""
with async_pause_setup(hass, SetupPhases.WAIT_IMPORT_PACKAGES):
# get_const will import a const module based on the version
# so we need to import it here to avoid it being imported
# in the event loop
await hass.async_add_import_executor_job(get_const, version)
if persistence_file is not None:
# Interpret relative paths to be in hass config folder.
# Absolute paths will be left as they are.