summaryrefslogtreecommitdiffstats
path: root/tradfriCli.nim
blob: fb39e014a8cdeac61c6c3e829b2565728dc67325 (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
40
41
import types, tradfri, deviceHelpers, json, os, strutils

let tradfriGateway = newTradfriGateway(
    host = "192.168.100.225",
    port = 5684,
    user = "ctucx",
    pass = "JrSGx6WkAVJUl53b"
  )


let devices = tradfriGateway.getDevices()

case paramStr(1):
of "list":
  echo "list of connected devices:"
  echo "======================="

  var id = 0

  for device in devices:
    echo $id & ": \tType:\t" & $device.`type`
    echo "\tName:\t" & $device.name
    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

of "devices-json-pretty":
  let devicesJson = %* devices
  echo pretty devicesJson