From a51ba250619e7164eee53b571b8e025f65727c3e Mon Sep 17 00:00:00 2001 From: Linus Dietz <45101649+Dielee@users.noreply.github.com> Date: Sat, 24 Jun 2023 18:02:56 +0200 Subject: [PATCH] Add mqtt broker port option --- src/config.yaml | 2 +- src/const.py | 2 +- src/mqtt.py | 9 ++++++++- src/settings.json | 1 + 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/config.yaml b/src/config.yaml index 23a7dac..ecfc6c3 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,6 +1,6 @@ name: "Volvo2Mqtt" description: "Volvo AAOS MQTT bridge" -version: "1.4.0" +version: "1.4.1" slug: "volvo2mqtt" init: false url: "https://github.com/Dielee/volvo2mqtt" diff --git a/src/const.py b/src/const.py index 706a8be..abdb19c 100644 --- a/src/const.py +++ b/src/const.py @@ -1,6 +1,6 @@ from config import settings -VERSION = "v1.4.0" +VERSION = "v1.4.1" OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2" VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles" diff --git a/src/mqtt.py b/src/mqtt.py index d7e4260..aaf43f3 100644 --- a/src/mqtt.py +++ b/src/mqtt.py @@ -2,6 +2,7 @@ import paho.mqtt.client as mqtt import json import volvo +from util import keys_exists from threading import Thread, Timer from datetime import datetime from babel.dates import format_datetime @@ -21,7 +22,13 @@ def connect(): client = mqtt.Client("volvoAAOS2mqtt") if settings["mqtt"]["username"] and settings["mqtt"]["password"]: client.username_pw_set(settings["mqtt"]["username"], settings["mqtt"]["password"]) - client.connect(settings["mqtt"]["broker"]) + port = 1883 + if keys_exists(settings["mqtt"], "port"): + conf_port = settings["mqtt"]["port"] + if isinstance(conf_port, int): + if conf_port > 0: + port = settings["mqtt"]["port"] + client.connect(settings["mqtt"]["broker"], port) client.loop_start() client.on_message = on_message client.on_disconnect = on_disconnect diff --git a/src/settings.json b/src/settings.json index f5c9b41..248945e 100644 --- a/src/settings.json +++ b/src/settings.json @@ -3,6 +3,7 @@ "babelLocale": "de", "mqtt": { "broker": "", + "port": 1883, "username": "", "password": "" },