From d8cce5e245bbae0a83e8bf72bd5dac932c772775 Mon Sep 17 00:00:00 2001 From: Dirk Alders Date: Thu, 9 Feb 2023 14:33:25 +0100 Subject: [PATCH] v1.0.0 --- smart_brain.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/smart_brain.py b/smart_brain.py index f328954..f5542fc 100644 --- a/smart_brain.py +++ b/smart_brain.py @@ -1,8 +1,11 @@ import config import function +import json import logging import mqtt +import os import report +import subprocess import time logger = logging.getLogger(config.APP_NAME) @@ -12,6 +15,31 @@ logger = logging.getLogger(config.APP_NAME) # TODO: Implement handling of warnings (videv element to show in webapp?) # TODO: implement garland (incl. day events like sunset, sunrise, ...) +VERS_MAJOR = 1 +VERS_MINOR = 0 +VERS_PATCH = 0 + +INFO_TOPIC = "__info__" +INFO_DATA = { + "app_name": os.path.splitext(os.path.basename(__file__))[0], + "version": { + "readable": "%d.%d.%d" % (VERS_MAJOR, VERS_MINOR, VERS_PATCH), + "major": VERS_MAJOR, + "minor": VERS_MINOR, + "patch": VERS_PATCH + }, + "git": { + "url": subprocess.check_output(["git", "config", "--get", "remote.origin.url"])[:-1].decode("utf-8"), + "ref": subprocess.check_output(["git", "log", "-1", '--format="%H"'])[2:-2].decode("utf-8") + } +} + + +def __info_publisher__(client, userdata, message): + data = json.loads(message.payload) + if data != INFO_DATA: + client.publish(INFO_TOPIC, json.dumps(INFO_DATA)) + if __name__ == "__main__": if config.DEBUG: @@ -21,6 +49,7 @@ if __name__ == "__main__": # mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER, password=config.MQTT_PASSWORD, name=config.APP_NAME) + mc.add_callback(INFO_TOPIC, __info_publisher__) func = function.all_functions(mc)