Smarthome Functionen
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

smart_brain.py 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import config
  2. import function
  3. import json
  4. import logging
  5. import mqtt
  6. import os
  7. import report
  8. import subprocess
  9. import time
  10. logger = logging.getLogger(config.APP_NAME)
  11. # TODO: Restructure nodered gui (own heating page - with circulation pump)
  12. # TODO: Rework devices to base.mqtt (pack -> set, ...)
  13. # TODO: Implement handling of warnings (videv element to show in webapp?)
  14. # TODO: implement garland (incl. day events like sunset, sunrise, ...)
  15. VERS_MAJOR = 1
  16. VERS_MINOR = 0
  17. VERS_PATCH = 1
  18. INFO_TOPIC = "__info__"
  19. INFO_DATA = {
  20. "app_name": os.path.splitext(os.path.basename(__file__))[0],
  21. "version": {
  22. "readable": "%d.%d.%d" % (VERS_MAJOR, VERS_MINOR, VERS_PATCH),
  23. "major": VERS_MAJOR,
  24. "minor": VERS_MINOR,
  25. "patch": VERS_PATCH
  26. },
  27. "git": {
  28. "url": subprocess.check_output(["git", "config", "--get", "remote.origin.url"])[:-1].decode("utf-8"),
  29. "ref": subprocess.check_output(["git", "log", "-1", '--format="%H"'])[1:-2].decode("utf-8")
  30. }
  31. }
  32. def __info_publisher__(client, userdata, message):
  33. data = json.loads(message.payload)
  34. if data != INFO_DATA:
  35. client.publish(INFO_TOPIC, json.dumps(INFO_DATA))
  36. if __name__ == "__main__":
  37. if config.DEBUG:
  38. report.appLoggingConfigure(None, None, ((config.APP_NAME, logging.DEBUG), ), fmt=report.SHORT_FMT, host='localhost', port=19996)
  39. else:
  40. report.stdoutLoggingConfigure(((config.APP_NAME, logging.INFO), ), report.SHORT_FMT)
  41. #
  42. mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
  43. password=config.MQTT_PASSWORD, name=config.APP_NAME)
  44. mc.add_callback(INFO_TOPIC, __info_publisher__)
  45. func = function.all_functions(mc)
  46. while (True):
  47. time.sleep(1)