add configurable client_id

This commit is contained in:
Benji
2018-11-06 19:53:17 +01:00
parent addc0fcb54
commit 2aaff0bb41
2 changed files with 9 additions and 2 deletions
+1
View File
@@ -4,6 +4,7 @@ mqtt:
username: user
password: password
topic_prefix: hostname
client_id: bt-mqtt-gateway
manager:
topic_subscription:
+8 -2
View File
@@ -1,11 +1,13 @@
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
class MqttClient:
#print({client_id})
def __init__(self, config):
self._config = config
self._mqttc = mqtt.Client(client_id='bt-mqtt-gateway', clean_session=False)
self._mqttc = mqtt.Client(client_id=self.client_id, clean_session=False)
if self.username is not None and self.password is not None:
self._auth = {'username': self.username, 'password': self.password}
@@ -25,6 +27,10 @@ class MqttClient:
port=self.port,
auth=self._auth)
@property
def client_id(self):
return self._config['client_id'] if 'client_id' in self._config else 'bt-mqtt-gateway'
@property
def hostname(self):
return self._config['host']