add configurable client_id
This commit is contained in:
@@ -4,6 +4,7 @@ mqtt:
|
||||
username: user
|
||||
password: password
|
||||
topic_prefix: hostname
|
||||
client_id: bt-mqtt-gateway
|
||||
|
||||
manager:
|
||||
topic_subscription:
|
||||
|
||||
@@ -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']
|
||||
|
||||
Reference in New Issue
Block a user