diff --git a/homeassistant/components/mysensors/gateway.py b/homeassistant/components/mysensors/gateway.py index 0a037dfce31..11f27f8a108 100644 --- a/homeassistant/components/mysensors/gateway.py +++ b/homeassistant/components/mysensors/gateway.py @@ -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.