From 796cf6af1fd883431dbdb4d1f7eb86c5c1d43912 Mon Sep 17 00:00:00 2001 From: Dmitrii Amelin Date: Wed, 25 Nov 2026 17:47:19 +0000 Subject: [PATCH] import mqtt in the import executor when @mqtt_trigger starts Since the legacy mqtt.py was removed, homeassistant.components.mqtt (and paho) was imported only by decorators/mqtt.py, which DecoratorRegistry.init() loads in the event loop, so Home Assistant logged a blocking call when MQTT isn't set up. MQTTTriggerDecorator.start() now imports it with async_import_module(), which runs the import in the import executor. --- custom_components/pyscript/decorators/mqtt.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/custom_components/pyscript/decorators/mqtt.py b/custom_components/pyscript/decorators/mqtt.py index d6019202..4b113786 100644 --- a/custom_components/pyscript/decorators/mqtt.py +++ b/custom_components/pyscript/decorators/mqtt.py @@ -4,15 +4,19 @@ import json import logging +from typing import TYPE_CHECKING import voluptuous as vol -from homeassistant.components import mqtt from homeassistant.core import CALLBACK_TYPE +from homeassistant.helpers.importlib import async_import_module from ..decorator_abc import DispatchData, TriggerDecorator from .base import AutoKwargsDecorator, ExpressionDecorator +if TYPE_CHECKING: + from homeassistant.components import mqtt + _LOGGER = logging.getLogger(__name__) @@ -54,6 +58,7 @@ async def start(self) -> None: """Start the MQTT trigger.""" await super().start() topic = self.args[0] + mqtt = await async_import_module(self.dm.hass, "homeassistant.components.mqtt") self.remove_listener_callback = await mqtt.async_subscribe( self.dm.hass, topic,