ctucx.git: nimtradfri

[nimlang] incomplete library to interact with ikea tradfri-gateways

commit 3f32d9cc93b3117f6ef1c0a9baff2fb28dfde00c
parent ebb05c1e00a8445f6efa5000c70167cd5b4ed651
Author: Isabelle K <hi@f2k1.de>
Date: Tue, 15 Sep 2020 13:42:50 +0200

add turn-on/off
1 file changed, 20 insertions(+), 2 deletions(-)
M
tradfriCli.nim
|
22
++++++++++++++++++++--
diff --git a/tradfriCli.nim b/tradfriCli.nim
@@ -51,6 +51,24 @@ if(paramCount() > 0):
 
     discard devices[deviceId].togglePowerState()
 
+  of "turn-off":
+    let deviceId = parseInt(paramStr(2))
+
+    if devices[deviceId].name == "":
+      echo "This device doesn't exist."
+      quit(0)
+
+    discard devices[deviceId].setPowerState(false)
+
+  of "turn-on":
+    let deviceId = parseInt(paramStr(2))
+
+    if devices[deviceId].name == "":
+      echo "This device doesn't exist."
+      quit(0)
+
+    discard devices[deviceId].setPowerState(true)
+
   of "setColor":
     let deviceId = parseInt(paramStr(2))
 

@@ -69,4 +87,4 @@ if(paramCount() > 0):
     echo pretty devicesJson
 
 else:
-  echo "tradfriCli\nUsage: ./trafriCli [params]\n\ndevices:\t\tLists devices. No additional options.\ntoggle:\t\t\tToggles device. Number from devices is needed as parameter\nsetColor:\t\tSets color for device. Number from devices is needed as parameter\ndevices-json:\t\tPrints out json of devices. No additional options\ndevices-json-pretty:\tSame as devices-json, but in pretty"-
\ No newline at end of file
+  echo "tradfriCli\nUsage: ./trafriCli [params]\n\ndevices:\t\tLists devices. No additional options.\ntoggle:\t\t\tToggles device. Number from devices is needed as parameter\nsetColor:\t\tSets color for device. Number from devices is needed as parameter\nturn-on:\t\tTurns the light on. Number from devices is needed as parameter\nturn-off:\t\tTurns the light off. Number from devices is needed as parameter\ndevices-json:\t\tPrints out json of devices. No additional options\ndevices-json-pretty:\tSame as devices-json, but in pretty"+
\ No newline at end of file