forked from Friendly0Fire/augustpy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.py
executable file
·54 lines (45 loc) · 1.73 KB
/
cli.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/python3
import augustpy.lock
import json
import time
import argparse
config = None
with open("config.json", "r") as config_file:
config = json.load(config_file)
if type(config) is dict:
config = [config]
locks = []
for lock_config in config:
lock = augustpy.lock.Lock(lock_config["bluetoothAddress"], lock_config["handshakeKey"], lock_config["handshakeKeyIndex"])
if "name" in lock_config:
lock.set_name(lock_config["name"])
locks.append(lock)
parser = argparse.ArgumentParser(description="Remotely control August locks.")
parser.add_argument('lock', metavar='L', type=str, nargs='+', help="The lock's name or address")
parser.add_argument('--lock', dest='action', action='store_const',
const='lock', help='Lock the lock')
parser.add_argument('--unlock', dest='action', action='store_const',
const='unlock', help='Lock the lock')
parser.add_argument('--status', dest='action', action='store_const',
const='status', help='Request lock status')
parser.add_argument('--disco', dest='disco', action='store_const',
const='disco', help='Disconnect from the lock')
parser.set_defaults(action='status')
args = parser.parse_args()
for lock in locks:
if lock.name in args.lock:
lock.connect()
if args.action == 'lock':
lock.lock()
print('locked')
time.sleep(4)
elif args.action == 'unlock':
lock.unlock()
print('unlocked')
time.sleep(4)
elif args.action == 'status':
print(lock.status())
time.sleep(4)
elif args.action == 'disco':
print(str(lock.disconnect()))
print("\n" + str(lock.disconnect()))