Merge "Add config option to set QOS of published messages"

This commit is contained in:
Jenkins 2016-12-21 17:48:47 +00:00 committed by Gerrit Code Review
commit 4cff75293e
1 changed files with 11 additions and 4 deletions

View File

@ -23,7 +23,7 @@ from lpmqtt import lp
class PushMQTT(object):
def __init__(self, hostname, port=1883, client_id=None,
keepalive=60, will=None, auth=None, tls=None):
keepalive=60, will=None, auth=None, tls=None, qos=0):
self.hostname = hostname
self.port = port
self.client_id = client_id
@ -31,18 +31,19 @@ class PushMQTT(object):
self.will = will
self.auth = auth
self.tls = tls
self.qos = qos
def publish_single(self, topic, msg):
publish.single(topic, msg, hostname=self.hostname,
port=self.port, client_id=self.client_id,
keepalive=self.keepalive, will=self.will,
auth=self.auth, tls=self.tls)
auth=self.auth, tls=self.tls, qos=self.qos)
def publish_multiple(self, topic, msg):
publish.multiple(topic, msg, hostname=self.hostname,
port=self.port, client_id=self.client_id,
keepalive=self.keepalive, will=self.will,
auth=self.auth, tls=self.tls)
auth=self.auth, tls=self.tls, qos=self.qos)
def process_event(event, base_topic):
@ -86,12 +87,18 @@ def main():
if mqtt_password:
auth['password'] = mqtt_password
base_topic = config.get('mqtt', 'base_topic')
# Max QOS
if config.has_option('mqtt', 'qos'):
mqtt_qos = config.getint('mqtt', 'qos')
else:
mqtt_qos = 0
mqttqueue = PushMQTT(
config.get('mqtt', 'hostname'),
port=mqtt_port,
keepalive=keepalive,
auth=auth)
auth=auth,
qos=mqtt_qos)
# IMAP email settings
imap_server = config.get('imap', 'hostname')