1
0

get_encryption_key.py 627 B

1234567891011121314151617181920212223242526272829
  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(sys.argv[1], sys.argv[2], password)
  15. except RuntimeError as e:
  16. print(e)
  17. exit(1)
  18. print("Key ID: " + result["key_id"])
  19. print("Encryption key: " + result["encryption_key"])
  20. if __name__ == "__main__":
  21. main()