MQTT Home Emulation
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import config
  2. import devdi
  3. import devdi.props as props
  4. import logging
  5. import mqtt
  6. import os
  7. import report
  8. import time
  9. # TODO: Implementation of missing devices in devices/__init__.py
  10. # TODO: Implementation of interface for external device stimulation
  11. logger = logging.getLogger(config.APP_NAME)
  12. if __name__ == "__main__":
  13. #
  14. # Logging
  15. #
  16. if config.DEBUG:
  17. report.appLoggingConfigure(None, 'stdout', ((config.APP_NAME, logging.DEBUG), ),
  18. target_level=logging.WARNING, fmt=report.SHORT_FMT, host='localhost', port=19996)
  19. else:
  20. report.stdoutLoggingConfigure(((config.APP_NAME, logging.WARNING), ), report.SHORT_FMT)
  21. #
  22. # MQTT Client
  23. #
  24. mc = mqtt.mqtt_client(host=config.MQTT_SERVER, port=config.MQTT_PORT, username=config.MQTT_USER,
  25. password=config.MQTT_PASSWORD, name=config.APP_NAME)
  26. #
  27. # Smarthome physical Devices
  28. #
  29. pd = devdi.physical_devices(mc)
  30. #
  31. # Smart Home Functionality
  32. #
  33. #######
  34. # GFW #
  35. #######
  36. loc = props.LOC_GFW
  37. # DIRK
  38. roo = props.ROO_DIR
  39. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  40. tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
  41. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  42. sml = pd.get(props.STG_MYA, loc, roo, props.FUN_MPP)
  43. tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_DEL)
  44. sml.register_power_on_instance(tml, sml.PROPERTIES[1])
  45. # FLOOR
  46. roo = props.ROO_FLO
  47. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  48. tml = pd.get(props.STG_ZGW, loc, roo, props.FUN_MAL)
  49. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  50. #######
  51. # FFW #
  52. #######
  53. loc = props.LOC_FFW
  54. # JULIAN
  55. roo = props.ROO_JUL
  56. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  57. tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  58. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  59. # LIVINGROOM
  60. roo = props.ROO_LIV
  61. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  62. tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  63. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  64. # SLEEP
  65. roo = props.ROO_SLP
  66. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  67. tml = pd.get(props.STG_ZFW, loc, roo, props.FUN_MAL)
  68. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  69. #######
  70. # FFE #
  71. #######
  72. loc = props.LOC_FFE
  73. # KITCHEN
  74. roo = props.ROO_KIT
  75. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_CIR)
  76. sml.auto_off(600)
  77. # LIVINGROOM
  78. roo = props.ROO_LIV
  79. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  80. tml = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  81. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  82. # SLEEP
  83. roo = props.ROO_SLP
  84. sml = pd.get(props.STG_SHE, loc, roo, props.FUN_MAL)
  85. tml = pd.get(props.STG_ZFE, loc, roo, props.FUN_MAL)
  86. sml.register_power_on_instance(tml, sml.PROPERTIES[0])
  87. while (True):
  88. time.sleep(1)