summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2020-09-14 19:18:35 +0200
committerctucx <c@ctu.cx>2020-09-14 19:18:35 +0200
commita68b196a324497583d77f5af12ddb4456e0ca91a (patch)
treec75ef0b93d757ed037693f5d8b57c6915fa9fa77
parent9bb979b39ea72c6ca3e9736a58e1e73ca5348876 (diff)
downloadnimtradfri-a68b196a324497583d77f5af12ddb4456e0ca91a.tar.gz
nimtradfri-a68b196a324497583d77f5af12ddb4456e0ca91a.tar.bz2
nimtradfri-a68b196a324497583d77f5af12ddb4456e0ca91a.zip
update
-rw-r--r--tradfriCli.nim15
1 files changed, 12 insertions, 3 deletions
diff --git a/tradfriCli.nim b/tradfriCli.nim
index 47abea7..fb39e01 100644
--- a/tradfriCli.nim
+++ b/tradfriCli.nim
@@ -1,4 +1,4 @@
-import types, tradfri, deviceHelpers, json, os
+import types, tradfri, deviceHelpers, json, os, strutils
let tradfriGateway = newTradfriGateway(
host = "192.168.100.225",
@@ -11,8 +11,8 @@ let tradfriGateway = newTradfriGateway(
let devices = tradfriGateway.getDevices()
case paramStr(1):
-of "list-devices":
- echo "list of all devices:"
+of "list":
+ echo "list of connected devices:"
echo "======================="
var id = 0
@@ -23,6 +23,15 @@ of "list-devices":
echo ""
id = id+1
+of "toggle":
+ let deviceId = parseInt(paramStr(2))
+
+ if devices[deviceId].name == "":
+ echo "This device doesn't exist."
+ quit(0)
+
+ discard devices[deviceId].togglePowerState()
+
of "devices-json":
let devicesJson = %* devices
echo devicesJson