1 from typing
import Dict, Callable
3 import paho.mqtt.client
as mqtt
7 """ MQTT Client factory """ 9 client_params = params.get(
'client', {})
10 client = mqtt.Client(**client_params)
13 tls_params = params.get(
'tls', {})
15 tls_insecure = tls_params.pop(
'tls_insecure',
False)
16 client.tls_set(**tls_params)
17 client.tls_insecure_set(tls_insecure)
20 account_params = params.get(
'account', {})
22 client.username_pw_set(**account_params)
25 message_params = params.get(
'message', {})
27 inflight = message_params.get(
'max_inflight_messages')
28 if inflight
is not None:
29 client.max_inflight_messages_set(inflight)
30 queue_size = message_params.get(
'max_queued_messages')
31 if queue_size
is not None:
32 client.max_queued_messages_set(queue_size)
33 retry = message_params.get(
'message_retry')
35 client.message_retry_set(retry)
38 userdata = params.get(
'userdata', {})
40 client.user_data_set(userdata)
43 will_params = params.get(
'will', {})
45 client.will_set(**will_params)
51 def extractor(topic_path):
52 if topic_path.startswith(
'~/'):
53 return '{}/{}'.format(mqtt_private_path, topic_path[2:])
58 __all__ = [
'default_mqtt_client_factory',
'create_private_path_extractor']
def create_private_path_extractor
def default_mqtt_client_factory