Zigbee2MQTT configuration for multimedia
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

c2r.py 877B

123456789101112131415161718192021222324252627282930
  1. #!/bin/python3
  2. #
  3. import re
  4. import sys
  5. try:
  6. src_file = sys.argv[1]
  7. dst_file = sys.argv[2]
  8. except IndexError:
  9. print(sys.argv[0], "<src> <dst>")
  10. sys.exit(17)
  11. try:
  12. with open(src_file, 'r') as fh:
  13. s = fh.read()
  14. except (PermissionError, FileNotFoundError) as e:
  15. print("Unable to open", '"' + src_file + '"')
  16. sys.exit(18)
  17. n = re.sub('^.*server: .*', ' server: mqtt://<mqtt_smarthome_hostname>', s, flags=re.MULTILINE)
  18. n = re.sub('^.*user: .*', ' user: <mqtt_smarthome_username>', n, flags=re.MULTILINE)
  19. n = re.sub('^.*password: .*', ' password: <mqtt_smarthome_password>', n, flags=re.MULTILINE)
  20. n = re.sub('^.*auth_token: .*', ' auth_token: <zigbee_auth_token>', n, flags=re.MULTILINE)
  21. try:
  22. with open(dst_file, 'w') as fh:
  23. fh.write(n)
  24. except PermissionError:
  25. print("Unable to write", '"' + dst_file + '"')
  26. sys.exit(19)