mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-04 02:48:12 +10:00
allow to set client id of mqtt connection in config, to support multiple instances of sungather
This commit is contained in:
@@ -64,6 +64,7 @@ exports:
|
||||
# topic: "inverter/{model}/registers" # [Optional] Default: "inverter/{model}/registers", Variable {model} will be replaced with model number of inverter
|
||||
# username: # [Optional] Username is MQTT server requires it
|
||||
# password: # [Optional] Password is MQTT server requires it
|
||||
# client_id: # [Optional] Client id for mqtt connection. Defaults to "SunGather", need to be set to different values if you want to run multiple instances of sungather.
|
||||
homeassistant: True # [Optional] Default False, Publish discovery and sensors for HomeAssistant
|
||||
ha_sensors: # [Optional] / [Required] ha_discovery: True, Topics to enable discovery for HA
|
||||
- name: "Daily Generation"
|
||||
|
||||
@@ -14,6 +14,7 @@ class export_mqtt(object):
|
||||
self.mqtt_config = {
|
||||
'host': config.get('host', None),
|
||||
'port': config.get('port', 1883),
|
||||
'client_id': config.get('client_id', 'SunGather'),
|
||||
'topic': config.get('topic', "inverter/{model}/registers").replace('{model}', inverter.getInverterModel(True)),
|
||||
'username': config.get('username', None),
|
||||
'password': config.get('password',None),
|
||||
@@ -26,8 +27,8 @@ class export_mqtt(object):
|
||||
if not self.mqtt_config['host']:
|
||||
logging.info(f"MQTT: Host config is required")
|
||||
return False
|
||||
|
||||
self.mqtt_client = mqtt.Client(client_id="SunGather")
|
||||
client_id = self.mqtt_config['client_id']
|
||||
self.mqtt_client = mqtt.Client(client_id)
|
||||
self.mqtt_client.on_connect = self.on_connect
|
||||
self.mqtt_client.on_disconnect = self.on_disconnect
|
||||
self.mqtt_client.on_publish = self.on_publish
|
||||
@@ -108,4 +109,4 @@ class export_mqtt(object):
|
||||
self.ha_discovery_published = True
|
||||
logging.info("MQTT: Published Home Assistant Discovery messages")
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user