Private variables start with _

This commit is contained in:
Gerrit Beine 2019-07-21 15:06:14 +02:00
parent a4098bf50d
commit 65a1323dc8

View file

@ -5,18 +5,18 @@ import paho.mqtt.client as mqtt
class Mqtt:
def __init__(self, config):
self.config = config
self._config = config
def connect(self):
self.client = mqtt.Client()
self.client.username_pw_set(self.config['user'], self.config['password'])
self.client.connect(self.config['host'], self.config['port'])
self.client.loop_start()
self._client = mqtt.Client()
self._client.username_pw_set(self._config['user'], self._config['password'])
self._client.connect(self._config['host'], self._config['port'])
self._client.loop_start()
def disconnect(self):
self.client.disconnect()
def publish(self, topic, payload):
topic = "{}/{}".format(self.config['topic'], topic)
topic = "{}/{}".format(self._config['topic'], topic)
logging.info("Publish %s: %s, %s, %s", topic, payload, self._config["qos"], self._config["retain"])
self._client.publish(topic, payload, self._config["qos"], self._config["retain"])