|
@@ -1,8 +1,11 @@
|
1
|
1
|
import config
|
2
|
2
|
import function
|
|
3
|
+import json
|
3
|
4
|
import logging
|
4
|
5
|
import mqtt
|
|
6
|
+import os
|
5
|
7
|
import report
|
|
8
|
+import subprocess
|
6
|
9
|
import time
|
7
|
10
|
|
8
|
11
|
logger = logging.getLogger(config.APP_NAME)
|
|
@@ -12,6 +15,31 @@ logger = logging.getLogger(config.APP_NAME)
|
12
|
15
|
# TODO: Implement handling of warnings (videv element to show in webapp?)
|
13
|
16
|
# TODO: implement garland (incl. day events like sunset, sunrise, ...)
|
14
|
17
|
|
|
18
|
+VERS_MAJOR = 1
|
|
19
|
+VERS_MINOR = 0
|
|
20
|
+VERS_PATCH = 0
|
|
21
|
+
|
|
22
|
+INFO_TOPIC = "__info__"
|
|
23
|
+INFO_DATA = {
|
|
24
|
+ "app_name": os.path.splitext(os.path.basename(__file__))[0],
|
|
25
|
+ "version": {
|
|
26
|
+ "readable": "%d.%d.%d" % (VERS_MAJOR, VERS_MINOR, VERS_PATCH),
|
|
27
|
+ "major": VERS_MAJOR,
|
|
28
|
+ "minor": VERS_MINOR,
|
|
29
|
+ "patch": VERS_PATCH
|
|
30
|
+ },
|
|
31
|
+ "git": {
|
|
32
|
+ "url": subprocess.check_output(["git", "config", "--get", "remote.origin.url"])[:-1].decode("utf-8"),
|
|
33
|
+ "ref": subprocess.check_output(["git", "log", "-1", '--format="%H"'])[2:-2].decode("utf-8")
|
|
34
|
+ }
|
|
35
|
+}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+def __info_publisher__(client, userdata, message):
|
|
39
|
+ data = json.loads(message.payload)
|
|
40
|
+ if data != INFO_DATA:
|
|
41
|
+ client.publish(INFO_TOPIC, json.dumps(INFO_DATA))
|
|
42
|
+
|
15
|
43
|
|
16
|
44
|
if __name__ == "__main__":
|
17
|
45
|
if config.DEBUG:
|
|
@@ -21,6 +49,7 @@ if __name__ == "__main__":
|
21
|
49
|
#
|
22
|
50
|
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
|
23
|
51
|
password=config.MQTT_PASSWORD, name=config.APP_NAME)
|
|
52
|
+ mc.add_callback(INFO_TOPIC, __info_publisher__)
|
24
|
53
|
|
25
|
54
|
func = function.all_functions(mc)
|
26
|
55
|
|