about summary refs log tree commit diff
path: root/fun/idual/idualctl
blob: 10a85eba0af04b2f2f122f0d1a54a065a3a38d55 (plain) (blame)
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
#!/usr/bin/env python

import idual
import sys

def help():
    print('Available commands:')
    for cmd in idual.commands:
        print('- ' + cmd)
    sys.exit(0)

def handle(ctrl, cmd):
    if cmd == 'help':
        help()
    elif cmd == 'wakey':
        ctrl.wakey()
        sys.exit(0)
    elif cmd == 'on':
        print('Turning on the lights')
        ctrl.send_cmd(cmd)
    elif cmd == 'off':
        print('Turning off the lights')
        ctrl.send_cmd(cmd)
    elif cmd in idual.commands:
        print('Sending ' + cmd + '-command')
        ctrl.send_cmd(cmd)
    else:
        print('unknown command \'' + cmd + '\'')
        sys.exit(1)

if __name__ == "__main__":
    if len(sys.argv) == 1:
        help()

    print('Initialising light controller')
    ctrl = idual.LightController()

    for cmd in sys.argv[1:]:
        handle(ctrl, cmd)