From 9b9334682ff212f83a3c6704f7e46eb985f605d2 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 12 Feb 2021 02:19:36 +0100 Subject: [PATCH] Still support default host/port fallback on mqtt.publish --- platypush/plugins/mqtt.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/platypush/plugins/mqtt.py b/platypush/plugins/mqtt.py index a0c53c95cc..fa1b3a9b75 100644 --- a/platypush/plugins/mqtt.py +++ b/platypush/plugins/mqtt.py @@ -135,7 +135,7 @@ class MqttPlugin(Plugin): return client @action - def publish(self, topic: str, msg: Any, host: Optional[str] = None, port: int = 1883, + def publish(self, topic: str, msg: Any, host: Optional[str] = None, port: Optional[int] = None, reply_topic: Optional[str] = None, timeout: int = 60, tls_cafile: Optional[str] = None, tls_certfile: Optional[str] = None, tls_keyfile: Optional[str] = None, tls_version: Optional[str] = None, @@ -146,8 +146,8 @@ class MqttPlugin(Plugin): :param topic: Topic/channel where the message will be delivered :param msg: Message to be sent. It can be a list, a dict, or a Message object. - :param host: MQTT broker hostname/IP. - :param port: MQTT broker port (default: 1883). + :param host: MQTT broker hostname/IP (default: default host configured on the plugin). + :param port: MQTT broker port (default: default port configured on the plugin). :param reply_topic: If a ``reply_topic`` is specified, then the action will wait for a response on this topic. :param timeout: If ``reply_topic`` is set, use this parameter to specify the maximum amount of time to wait for a response (default: 60 seconds). @@ -179,6 +179,10 @@ class MqttPlugin(Plugin): except: pass + host = host or self.host + port = port or self.port or 1883 + assert host, 'No host specified' + client = self._get_client(tls_cafile=tls_cafile, tls_certfile=tls_certfile, tls_keyfile=tls_keyfile, tls_version=tls_version, tls_ciphers=tls_ciphers, tls_insecure=tls_insecure, username=username, password=password)