Reduce overhead to process and publish MQTT messages (#99457)
This commit is contained in:
parent
5a8fc43212
commit
7c87b38a23
1 changed files with 3 additions and 2 deletions
|
@ -110,7 +110,7 @@ def publish(
|
|||
encoding: str | None = DEFAULT_ENCODING,
|
||||
) -> None:
|
||||
"""Publish message to a MQTT topic."""
|
||||
hass.add_job(async_publish, hass, topic, payload, qos, retain, encoding)
|
||||
hass.create_task(async_publish(hass, topic, payload, qos, retain, encoding))
|
||||
|
||||
|
||||
async def async_publish(
|
||||
|
@ -376,6 +376,7 @@ class MQTT:
|
|||
) -> None:
|
||||
"""Initialize Home Assistant MQTT client."""
|
||||
self.hass = hass
|
||||
self.loop = hass.loop
|
||||
self.config_entry = config_entry
|
||||
self.conf = conf
|
||||
|
||||
|
@ -806,7 +807,7 @@ class MQTT:
|
|||
self, _mqttc: mqtt.Client, _userdata: None, msg: mqtt.MQTTMessage
|
||||
) -> None:
|
||||
"""Message received callback."""
|
||||
self.hass.add_job(self._mqtt_handle_message, msg)
|
||||
self.loop.call_soon_threadsafe(self._mqtt_handle_message, msg)
|
||||
|
||||
@lru_cache(None) # pylint: disable=method-cache-max-size-none
|
||||
def _matching_subscriptions(self, topic: str) -> list[Subscription]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue