提交 7465949f 编写于 作者: M Moisés Guimarães

passing dictionaries directly to functions using named params.

Signed-off-by: NMoisés Guimarães <guimaraes.moises@gmail.com>
上级 10ae1af7
......@@ -25,6 +25,7 @@ import paho.mqtt as mqtt
def _do_publish(client):
"""Internal function"""
message = client._userdata.pop()
if isinstance(message, dict):
......@@ -40,6 +41,8 @@ def _do_publish(client):
def _on_connect(client, userdata, flags, rc):
"""Internal callback"""
#pylint: disable=invalid-name, unused-argument
if rc == 0:
_do_publish(client)
else:
......@@ -48,6 +51,8 @@ def _on_connect(client, userdata, flags, rc):
def _on_publish(client, userdata, mid):
"""Internal callback"""
#pylint: disable=unused-argument
if len(userdata) == 0:
client.disconnect()
else:
......@@ -128,13 +133,10 @@ def multiple(msgs, hostname="localhost", port=1883, client_id="", keepalive=60,
client.on_connect = _on_connect
if auth is not None:
client.username_pw_set(auth['username'], auth.get('password'))
client.username_pw_set(**auth)
if will is not None:
client.will_set(will['topic'],
will.get('payload'),
will.get('qos', 0),
will.get('retain', False))
client.will_set(**will)
if tls is not None:
if isinstance(tls, dict):
......
......@@ -19,7 +19,6 @@ returns one or messages matching a set of topics, and callback() which allows
you to pass a callback for processing of messages.
"""
import ssl
import paho.mqtt.client as paho
import paho.mqtt as mqtt
......@@ -129,20 +128,16 @@ def callback(callback, topics, qos=0, userdata=None, hostname="localhost",
'qos':qos,
'userdata':userdata}
client = paho.Client(client_id=client_id,
userdata=callback_userdata, protocol=protocol, transport=transport)
client = paho.Client(client_id=client_id, userdata=callback_userdata,
protocol=protocol, transport=transport)
client.on_message = _on_message_callback
client.on_connect = _on_connect
if auth is not None:
client.username_pw_set(auth['username'],
auth.get('password'))
client.username_pw_set(**auth)
if will is not None:
client.will_set(will['topic'],
will.get('payload'),
will.get('qos', 0),
will.get('retain', False))
client.will_set(**will)
if tls is not None:
if isinstance(tls, dict):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册