mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 18:28:14 +02:00
Ensure paho.mqtt.client is imported in the executor (#118412)
fixes #118405
This commit is contained in:
@ -39,9 +39,11 @@ from homeassistant.core import (
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.importlib import async_import_module
|
||||
from homeassistant.helpers.start import async_at_started
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.loader import bind_hass
|
||||
from homeassistant.setup import SetupPhases, async_pause_setup
|
||||
from homeassistant.util.async_ import create_eager_task
|
||||
from homeassistant.util.collection import chunked_or_all
|
||||
from homeassistant.util.logging import catch_log_exception, log_exception
|
||||
@ -491,13 +493,13 @@ class MQTT:
|
||||
"""Handle HA stop."""
|
||||
await self.async_disconnect()
|
||||
|
||||
def start(
|
||||
async def async_start(
|
||||
self,
|
||||
mqtt_data: MqttData,
|
||||
) -> None:
|
||||
"""Start Home Assistant MQTT client."""
|
||||
self._mqtt_data = mqtt_data
|
||||
self.init_client()
|
||||
await self.async_init_client()
|
||||
|
||||
@property
|
||||
def subscriptions(self) -> list[Subscription]:
|
||||
@ -528,8 +530,11 @@ class MQTT:
|
||||
mqttc.on_socket_open = self._async_on_socket_open
|
||||
mqttc.on_socket_register_write = self._async_on_socket_register_write
|
||||
|
||||
def init_client(self) -> None:
|
||||
async def async_init_client(self) -> None:
|
||||
"""Initialize paho client."""
|
||||
with async_pause_setup(self.hass, SetupPhases.WAIT_IMPORT_PACKAGES):
|
||||
await async_import_module(self.hass, "paho.mqtt.client")
|
||||
|
||||
mqttc = MqttClientSetup(self.conf).client
|
||||
# on_socket_unregister_write and _async_on_socket_close
|
||||
# are only ever called in the event loop
|
||||
|
Reference in New Issue
Block a user