2022-12-19 10:35:20 +01:00
|
|
|
import config
|
2023-12-23 07:50:24 +01:00
|
|
|
import devdi.devices
|
2022-12-19 10:35:20 +01:00
|
|
|
import function
|
2023-02-09 14:33:25 +01:00
|
|
|
import json
|
2022-12-19 10:35:20 +01:00
|
|
|
import logging
|
|
|
|
import mqtt
|
2023-02-09 14:33:25 +01:00
|
|
|
import os
|
2022-12-19 10:35:20 +01:00
|
|
|
import report
|
2023-02-09 14:33:25 +01:00
|
|
|
import subprocess
|
2022-12-19 10:35:20 +01:00
|
|
|
import time
|
|
|
|
|
|
|
|
logger = logging.getLogger(config.APP_NAME)
|
|
|
|
|
2023-01-28 14:32:52 +01:00
|
|
|
|
2023-02-09 14:33:25 +01:00
|
|
|
VERS_MAJOR = 1
|
2023-02-15 07:11:32 +01:00
|
|
|
VERS_MINOR = 2
|
2023-03-26 11:00:18 +02:00
|
|
|
VERS_PATCH = 6
|
2023-02-09 14:33:25 +01:00
|
|
|
|
|
|
|
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"),
|
2023-02-09 15:55:21 +01:00
|
|
|
"ref": subprocess.check_output(["git", "log", "-1", '--format="%H"'])[1:-2].decode("utf-8")
|
2023-02-09 14:33:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def __info_publisher__(client, userdata, message):
|
|
|
|
data = json.loads(message.payload)
|
|
|
|
if data != INFO_DATA:
|
|
|
|
client.publish(INFO_TOPIC, json.dumps(INFO_DATA))
|
|
|
|
|
2022-12-19 10:35:20 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-10-29 15:10:06 +01:00
|
|
|
#
|
|
|
|
# Logging
|
|
|
|
#
|
2022-12-19 10:35:20 +01:00
|
|
|
if config.DEBUG:
|
2023-02-15 09:12:05 +01:00
|
|
|
report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
|
|
|
|
target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
|
2022-12-19 10:35:20 +01:00
|
|
|
else:
|
2023-10-31 09:03:13 +01:00
|
|
|
report.stdoutLoggingConfigure(((config.APP_NAME, config.LOGLEVEL), ), report.SHORT_FMT)
|
2023-10-29 15:10:06 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# MQTT Client
|
2022-12-19 10:35:20 +01:00
|
|
|
#
|
2022-12-25 16:31:22 +01:00
|
|
|
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 10:35:20 +01:00
|
|
|
|
2023-10-29 15:10:06 +01:00
|
|
|
#
|
|
|
|
# Smarthome physical Devices
|
|
|
|
#
|
2023-12-23 07:50:24 +01:00
|
|
|
pd = devdi.devices.physical_devices(mc)
|
2023-10-29 15:10:06 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Smarthome physical Devices
|
|
|
|
#
|
2023-12-23 07:50:24 +01:00
|
|
|
vd = devdi.devices.videv_devices(mc)
|
2023-10-29 15:10:06 +01:00
|
|
|
|
|
|
|
#
|
|
|
|
# Smart Home Functionality
|
|
|
|
#
|
|
|
|
func = function.all_functions(mc, pd, vd)
|
2022-12-19 10:35:20 +01:00
|
|
|
|
|
|
|
while (True):
|
|
|
|
time.sleep(1)
|