mirror of
https://github.com/alexhopeoconnor/SunGather.git
synced 2026-10-13 14:51:20 +10:00
Merge pull request #52 from Eigenbaukombinat/main
allow to set client id of mqtt connection in config, to support multi…
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"
|
||||
|
||||
@@ -11,10 +11,12 @@ class export_mqtt(object):
|
||||
|
||||
# Configure MQTT
|
||||
def configure(self, config, inverter):
|
||||
model = inverter.getInverterModel(True)
|
||||
self.mqtt_config = {
|
||||
'host': config.get('host', None),
|
||||
'port': config.get('port', 1883),
|
||||
'topic': config.get('topic', "inverter/{model}/registers").replace('{model}', inverter.getInverterModel(True)),
|
||||
'client_id': config.get('client_id', f'SunGather-{model}'),
|
||||
'topic': config.get('topic', f"inverter/{model}/registers"),
|
||||
'username': config.get('username', None),
|
||||
'password': config.get('password',None),
|
||||
'homeassistant': config.get('homeassistant',False)
|
||||
@@ -26,8 +28,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
|
||||
|
||||
Reference in New Issue
Block a user