about summary refs log tree commit diff
path: root/fun/idual/idualctl
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2020-04-26T14·50+0100
committerVincent Ambo <tazjin@google.com>2020-04-26T14·50+0100
commit8681ac787e7b03e544cbfbcdf7b2d926c037c70c (patch)
tree65b6c357af3a269e35d111a8ff213028af3b5c36 /fun/idual/idualctl
parenta34f7ef11999636deffd47f8efdc6847d4c676d7 (diff)
feat(fun/idual): Introduce real CLI that can send all commands r/692
Adds an idualctl CLI that can be used to control the lights.
Diffstat (limited to 'fun/idual/idualctl')
-rw-r--r--fun/idual/idualctl39
1 files changed, 39 insertions, 0 deletions
diff --git a/fun/idual/idualctl b/fun/idual/idualctl
new file mode 100644
index 000000000000..10a85eba0af0
--- /dev/null
+++ b/fun/idual/idualctl
@@ -0,0 +1,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)