MQTT Home Emulation
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

home_emulation.py 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import config
  2. import devdi.devices
  3. import home
  4. import logging
  5. import mqtt
  6. import os
  7. import report
  8. import user_interface
  9. # TODO: Add some test for smart_brain
  10. # TODO: Implementation of missing devices in devices/__init__.py
  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.devices.physical_devices(mc)
  30. #
  31. # Smart Home Functionality
  32. #
  33. home.functions(pd)
  34. #
  35. # User Interface
  36. #
  37. ui = user_interface.user_interface()
  38. # Add the device commands
  39. for d in pd.values():
  40. try:
  41. for cmd in d.user_cmds:
  42. ui.add_command(cmd, d.user_cmds[cmd])
  43. except AttributeError:
  44. pass # device seems to have no user commands
  45. ui.run()