mirror of
https://github.com/home-assistant/core.git
synced 2025-07-11 07:17:12 +00:00
Ensure paho.mqtt.client is imported in the executor (#118412)
fixes #118405
This commit is contained in:
parent
5fae2bd7c5
commit
1743d1700d
@ -244,7 +244,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
websocket_api.async_register_command(hass, websocket_subscribe)
|
websocket_api.async_register_command(hass, websocket_subscribe)
|
||||||
websocket_api.async_register_command(hass, websocket_mqtt_info)
|
websocket_api.async_register_command(hass, websocket_mqtt_info)
|
||||||
hass.data[DATA_MQTT] = mqtt_data = MqttData(config=mqtt_yaml, client=client)
|
hass.data[DATA_MQTT] = mqtt_data = MqttData(config=mqtt_yaml, client=client)
|
||||||
client.start(mqtt_data)
|
await client.async_start(mqtt_data)
|
||||||
|
|
||||||
# Restore saved subscriptions
|
# Restore saved subscriptions
|
||||||
if mqtt_data.subscriptions_to_restore:
|
if mqtt_data.subscriptions_to_restore:
|
||||||
|
@ -39,9 +39,11 @@ from homeassistant.core import (
|
|||||||
)
|
)
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
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.start import async_at_started
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.loader import bind_hass
|
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.async_ import create_eager_task
|
||||||
from homeassistant.util.collection import chunked_or_all
|
from homeassistant.util.collection import chunked_or_all
|
||||||
from homeassistant.util.logging import catch_log_exception, log_exception
|
from homeassistant.util.logging import catch_log_exception, log_exception
|
||||||
@ -491,13 +493,13 @@ class MQTT:
|
|||||||
"""Handle HA stop."""
|
"""Handle HA stop."""
|
||||||
await self.async_disconnect()
|
await self.async_disconnect()
|
||||||
|
|
||||||
def start(
|
async def async_start(
|
||||||
self,
|
self,
|
||||||
mqtt_data: MqttData,
|
mqtt_data: MqttData,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Start Home Assistant MQTT client."""
|
"""Start Home Assistant MQTT client."""
|
||||||
self._mqtt_data = mqtt_data
|
self._mqtt_data = mqtt_data
|
||||||
self.init_client()
|
await self.async_init_client()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subscriptions(self) -> list[Subscription]:
|
def subscriptions(self) -> list[Subscription]:
|
||||||
@ -528,8 +530,11 @@ class MQTT:
|
|||||||
mqttc.on_socket_open = self._async_on_socket_open
|
mqttc.on_socket_open = self._async_on_socket_open
|
||||||
mqttc.on_socket_register_write = self._async_on_socket_register_write
|
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."""
|
"""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
|
mqttc = MqttClientSetup(self.conf).client
|
||||||
# on_socket_unregister_write and _async_on_socket_close
|
# on_socket_unregister_write and _async_on_socket_close
|
||||||
# are only ever called in the event loop
|
# are only ever called in the event loop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user