smart_brain/smart_brain.py

58 lines
1.7 KiB
Python
Raw Normal View History

import config
import function
2023-02-09 14:33:25 +01:00
import json
import logging
import mqtt
2023-02-09 14:33:25 +01:00
import os
import report
2023-02-09 14:33:25 +01:00
import subprocess
import time
logger = logging.getLogger(config.APP_NAME)
2023-01-30 12:22:59 +01:00
# TODO: Restructure nodered gui (own heating page - with circulation pump)
2023-01-28 14:32:52 +01:00
# TODO: Rework devices to base.mqtt (pack -> set, ...)
# TODO: Implement handling of warnings (videv element to show in webapp?)
2023-02-06 12:42:44 +01:00
# TODO: implement garland (incl. day events like sunset, sunrise, ...)
2023-01-28 14:32:52 +01:00
2023-02-09 14:33:25 +01:00
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:
report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996)
else:
2022-12-26 09:56:56 +01:00
report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO), ), report.SHORT_FMT)
#
mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
password=config.MQTT_PASSWORD, name=config.APP_NAME)
2023-02-09 14:33:25 +01:00
mc.add_callback(INFO_TOPIC, __info_publisher__)
2022-12-19 16:11:35 +01:00
func = function.all_functions(mc)
while (True):
time.sleep(1)