File: get_encryption_key.py

package info (click to toggle)
pyswitchbot 0.76.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: python: 14,265; makefile: 2
file content (28 lines) | stat: -rwxr-xr-x 624 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python3
import getpass
import sys

from switchbot import SwitchbotLock


def main():
    if len(sys.argv) < 3:
        print(f"Usage: {sys.argv[0]} <device_mac> <username> [<password>]")
        sys.exit(1)

    password = getpass.getpass() if len(sys.argv) == 3 else sys.argv[3]

    try:
        result = SwitchbotLock.retrieve_encryption_key(
            sys.argv[1], sys.argv[2], password
        )
    except RuntimeError as e:
        print(e)
        sys.exit(1)

    print("Key ID: " + result["key_id"])
    print("Encryption key: " + result["encryption_key"])


if __name__ == "__main__":
    main()