JoshDi

plugin_send.py

Apr 1st, 2018
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. #           Broadlink RM2 Python Plugin for Domoticz
  2. #
  3. #           Dev. Platform : Win10 x64 & Py 3.5.3 x86
  4. #
  5. #           Author:     zak45, 2017
  6. #
  7. #   Send learned command stored in ini file
  8. #   One param required: ini file full path name
  9. #   Can be used stand alone
  10. #
  11.  
  12. #
  13. # Main Import
  14. import broadlink
  15. import configparser
  16. import sys
  17. import os
  18.  
  19. #
  20. sendCommand = ""
  21. brohost = ""
  22. bromac = ""
  23.  
  24. #
  25.  
  26. def send():
  27.     global sendCommand
  28.  
  29.     if not sendCommand:
  30.         print('Nothing to send')
  31.         sys.exit(3)
  32.  
  33.     sendCommand = bytes.fromhex(sendCommand)
  34.  
  35.     try:
  36.         device.send_data(sendCommand)
  37.         print( "Code Sent....")
  38.  
  39.     except:
  40.         raise
  41.         return False
  42.  
  43.     return True
  44.  
  45.  
  46. def broadlinkConnect():
  47.     global device, brohost, bromac
  48.  
  49.     try:
  50.         device = broadlink.rm(host=(brohost,80), mac=bytearray.fromhex(bromac), devtype=0x279d)
  51.         device.auth()
  52.         device.host
  53.         print( "Connected to Broadlink device.")
  54.     except:
  55.         print( "Error Connecting to Broadlink device....")
  56.         sys.exit(2)
  57.  
  58.     return True
  59.  
  60. path=sys.argv[1]
  61.  
  62. if not os.path.exists(path):
  63.     print(' ini file not found: ' + path)
  64.     sys.exit(1)
  65.  
  66. config = configparser.ConfigParser()
  67. config.read(path)
  68. Unit=config.get("DEFAULT", "Unit")
  69. brohost=config.get("Device", "host")
  70. bromac=config.get("Device", "mac")
  71. sendCommand = config.get("LearnedCode", Unit)
  72. broadlinkConnect()
  73. send()
Advertisement
Add Comment
Please, Sign In to add comment