1 """Async wrappings for mqtt client."""
3 from __future__
import annotations
5 from functools
import lru_cache
6 from types
import TracebackType
7 from typing
import Self
9 from paho.mqtt.client
import Client
as MQTTClient
17 @lru_cache(maxsize=_MQTT_LOCK_COUNT)
22 @lru_cache(maxsize=_MQTT_LOCK_COUNT)
25 exc_type: type[BaseException] |
None,
26 exc_value: BaseException |
None,
27 traceback: TracebackType |
None,
31 @lru_cache(maxsize=_MQTT_LOCK_COUNT)
32 def acquire(self, blocking: bool =
False, timeout: int = -1) ->
None:
33 """Acquire the lock."""
35 @lru_cache(maxsize=_MQTT_LOCK_COUNT)
37 """Release the lock."""
40 class AsyncMQTTClient(MQTTClient):
43 Wrapper around paho.mqtt.client.Client to remove the locking
44 that is not needed since we are running in an async event loop.
50 All the threading locks are replaced with NullLock
51 since the client is running in an async event loop
52 and will never run in multiple threads.
None __exit__(self, type[BaseException]|None exc_type, BaseException|None exc_value, TracebackType|None traceback)
None acquire(self, bool blocking=False, int timeout=-1)