summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIsabelle K <hi@f2k1.de>2020-09-15 13:34:35 +0200
committerIsabelle K <hi@f2k1.de>2020-09-15 13:34:35 +0200
commit9687803352bc2f7c4ebff0af46c099e800f0a008 (patch)
treebf7c2a53cd2dcd67d60692c0915cdab84f9d6307
parent4057993960872f3718c35e1cb6f3d29b8d4590a5 (diff)
downloadnimtradfri-9687803352bc2f7c4ebff0af46c099e800f0a008.tar.gz
nimtradfri-9687803352bc2f7c4ebff0af46c099e800f0a008.tar.bz2
nimtradfri-9687803352bc2f7c4ebff0af46c099e800f0a008.zip
update
-rw-r--r--tradfriCli.nim81
1 files changed, 51 insertions, 30 deletions
diff --git a/tradfriCli.nim b/tradfriCli.nim
index 4bcee0c..1d018a6 100644
--- a/tradfriCli.nim
+++ b/tradfriCli.nim
@@ -1,5 +1,5 @@
import json, os, strutils
-import tradfri
+import tradfri, deviceTypes
let tradfriGateway = newTradfriGateway(
host = "192.168.100.225",
@@ -11,41 +11,62 @@ let tradfriGateway = newTradfriGateway(
let devices = tradfriGateway.getDevices()
-case paramStr(1):
-of "list":
- echo "list of connected devices:"
- echo "======================="
+if(paramCount() > 0):
+ case paramStr(1):
+ of "devices":
+ echo "list of connected devices:"
+ echo "======================="
- var id = 0
+ var id = 0
- for device in devices:
- echo $id & ": \tType:\t" & $device.`type`
- echo "\tName:\t" & $device.name
- echo ""
- id = id+1
+ for device in devices:
+ if device.alive == false:
+ stdout.write "\u001b[30;1m"
+ echo $id & ": \tType:\t\t" & $device.`type`
+ echo "\tName:\t\t" & $device.name
+ echo "\tAlive:\t\t" & $device.alive
+ if device.type == Lightbulb:
+ stdout.write "\tLightSpectrum:\t"
+ if device.state.lightSpectrum == RGB:
+ echo "🎨 RGB"
+ elif device.state.lightSpectrum == White:
+ echo "⚪ White"
+ elif device.state.lightSpectrum == None:
+ echo "☐ None"
+ if device.state.lightPowered:
+ echo "\tPowered:\t💡 yes"
+ else:
+ echo "\tPowered:\tno"
+ if device.info.power == Battery:
+ echo "\tBattery:\t" & $device.info.battery & "%"
+ echo "\u001b[0m"
+ id = id+1
-of "toggle":
- let deviceId = parseInt(paramStr(2))
+ of "toggle":
+ let deviceId = parseInt(paramStr(2))
- if devices[deviceId].name == "":
- echo "This device doesn't exist."
- quit(0)
+ if devices[deviceId].name == "":
+ echo "This device doesn't exist."
+ quit(0)
- discard devices[deviceId].togglePowerState()
+ discard devices[deviceId].togglePowerState()
-of "setColor":
- let deviceId = parseInt(paramStr(2))
+ of "setColor":
+ let deviceId = parseInt(paramStr(2))
- if devices[deviceId].name == "":
- echo "This device doesn't exist."
- quit(0)
+ if devices[deviceId].name == "":
+ echo "This device doesn't exist."
+ quit(0)
- discard devices[deviceId].setColorXYfromHex(paramStr(3))
-
-of "devices-json":
- let devicesJson = %* devices
- echo devicesJson
+ discard devices[deviceId].setColorXYfromHex(paramStr(3))
-of "devices-json-pretty":
- let devicesJson = %* devices
- echo pretty devicesJson
+ of "devices-json":
+ let devicesJson = %* devices
+ echo devicesJson
+
+ of "devices-json-pretty":
+ let devicesJson = %* devices
+ 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