forked from JasonCarter80/concord232
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concord232_client
executable file
·140 lines (112 loc) · 4.02 KB
/
concord232_client
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env python
import argparse
import pprint
import prettytable
from concord232 import client
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('command')
parser.add_argument('--zone', default=None, type=int,
help='Zone number for zone-related commands')
parser.add_argument('--partition', default=None, type=int,
help='Partition number for partition-related commands')
parser.add_argument('--user', default=None, type=int,
help='User number for user-related commands')
parser.add_argument('--master', default=None,
help='Master PIN for commands that require it')
parser.add_argument('--host', default='localhost:5007',
help='Host and port (localhost:5007)')
parser.add_argument('--keys', default='',
help='Key Presses to Send')
parser.add_argument('--group', default='False',
help='Group the Key Input as One Command ')
args = parser.parse_args()
return args
def do_list(clnt, args):
for zone in clnt.list_zones():
pprint.pprint(zone)
def do_list_partitions(clnt, args):
for part in clnt.list_partitions():
pprint.pprint(part)
def do_arm(clnt, args):
if args.command == 'arm-stay':
mode = 'stay'
elif args.command == 'arm-stay-silent':
mode = 'stay-silent'
elif args.command == 'arm-exit':
mode = 'exit'
else:
mode = 'auto'
clnt.arm(mode)
def do_disarm(clnt, args):
if not args.master:
print('Master pin required')
return
clnt.disarm(args.master)
def do_keys(clnt, args):
if args.group:
group = True
if not args.keys:
print('Keys required')
return
clnt.send_keys(args.keys, group)
def do_summary(clnt, args):
t = prettytable.PrettyTable(['Zone', 'Name', 'Bypass', 'Status','Type'])
for zone in sorted(clnt.list_zones(), key=lambda k: k['number']) :
t.add_row(['%i' % zone['number'], zone['name'],
zone['state'] ,
'%s' % (zone['state'] or False),
zone['type']])
print(t)
t = prettytable.PrettyTable(['Partition', 'Zones', 'Status','Level'])
for i, part in enumerate(clnt.list_partitions()):
if part['zones'] > 0:
status = "Disarmed" if part['arming_level'] == "Off" else "Armed"
t.add_row(['%i' % part['number'], part['zones'],status,part['arming_level']])
print(t)
def do_show(clnt, args):
if args.zone:
for zone in clnt.list_zones():
if zone['number'] == args.zone:
pprint.pprint(zone)
return
print('No such zone `%s\'' % args.zone)
elif args.partition:
for part in clnt.list_partitions():
if part['number'] == args.partition:
pprint.pprint(part)
return
print('No such partition `%s\'' % args.partition)
else:
print('Zone or Partition required')
def do_events(clnt, args):
while True:
events = clnt.get_events()
if events:
for event in events:
print(event)
def do_version(clnt, args):
print(clnt.get_version())
def main():
args = parse_args()
url = 'http://%s:%s' % tuple(args.host.split(':', 1))
clnt = client.Client(url)
if args.command == 'list':
do_list(clnt, args)
elif args.command in ['arm', 'arm-stay', 'arm-stay-silent',
'arm-exit', 'arm-auto']:
do_arm(clnt, args)
elif args.command == 'disarm':
do_disarm(clnt, args)
elif args.command == 'keys':
do_keys(clnt, args)
elif args.command == 'partitions':
do_list_partitions(clnt, args)
elif args.command == 'summary':
do_summary(clnt, args)
elif args.command == 'show':
do_show(clnt, args)
elif args.command == 'version':
do_version(clnt, args)
if __name__ == '__main__':
main()