1
0

get_encryption_key.py 649 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import getpass
  3. import sys
  4. from switchbot import SwitchbotLock
  5. def main():
  6. if len(sys.argv) < 3:
  7. print(f"Usage: {sys.argv[0]} <device_mac> <username> [<password>]")
  8. exit(1)
  9. if len(sys.argv) == 3:
  10. password = getpass.getpass()
  11. else:
  12. password = sys.argv[3]
  13. try:
  14. result = SwitchbotLock.retrieve_encryption_key(
  15. sys.argv[1], sys.argv[2], password
  16. )
  17. except RuntimeError as e:
  18. print(e)
  19. exit(1)
  20. print("Key ID: " + result["key_id"])
  21. print("Encryption key: " + result["encryption_key"])
  22. if __name__ == "__main__":
  23. main()