summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorctucx <c@ctu.cx>2020-09-15 16:03:10 +0200
committerctucx <c@ctu.cx>2020-09-15 16:03:10 +0200
commit2ef422f2177aa26ca822e5dcecd56eb5ac3f6294 (patch)
tree277bcc5b2eb5cf249cddc87f629e2e98245e2bb4
parent4317db05e4836d05125ad6505f1dd5e4e0cf2e3f (diff)
downloadnimtradfri-2ef422f2177aa26ca822e5dcecd56eb5ac3f6294.tar.gz
nimtradfri-2ef422f2177aa26ca822e5dcecd56eb5ac3f6294.tar.bz2
nimtradfri-2ef422f2177aa26ca822e5dcecd56eb5ac3f6294.zip
update
-rw-r--r--groupTypes.nim1
-rw-r--r--groups.nim20
-rw-r--r--listGroups.nim (renamed from test.nim)4
-rw-r--r--mappings.nim12
4 files changed, 25 insertions, 12 deletions
diff --git a/groupTypes.nim b/groupTypes.nim
index 6b5a9f2..c232daa 100644
--- a/groupTypes.nim
+++ b/groupTypes.nim
@@ -12,7 +12,6 @@ type
id*: int
powerState*: bool
dimmerValue*: int
- trigger*: int
sceneId*: int
devices*: seq[TradfriDevice]
diff --git a/groups.nim b/groups.nim
index 03f4243..43567a1 100644
--- a/groups.nim
+++ b/groups.nim
@@ -1,8 +1,8 @@
-import json, strutils, options
+import json, strutils, sequtils, options
import coapClient
-import gatewayTypes, groupTypes
-import mappings, helpers
+import gatewayTypes, groupTypes, deviceTypes
+import mappings, helpers, devices
proc operateGroup* (group: TradfriGroup, action: TradfriGroupAction): bool =
var requestParams = %* {}
@@ -21,11 +21,21 @@ proc operateGroup* (group: TradfriGroup, action: TradfriGroupAction): bool =
proc getGroup* (gatewayRef: TradfriGatewayRef, groupId: int): TradfriGroup =
- let request = makeCoapRequest(gatewayRef.host, gatewayRef.port, "get", gatewayRef.user, gatewayRef.pass, EndpointDevices & $groupId, %* {})
+ let request = makeCoapRequest(gatewayRef.host, gatewayRef.port, "get", gatewayRef.user, gatewayRef.pass, EndpointGroups & $groupId, %* {})
+
+ var devices = newSeq[TradfriDevice]()
+ for deviceId in request[ParameterDeviceIds]["15002"]["9003"]:
+ devices.add(gatewayRef.getDevice(deviceId.getInt))
result = TradfriGroup(
gatewayRef: gatewayRef,
-
+ name: request[ParameterName].getStr,
+ createdAt: request[ParameterCreatedAt].getInt,
+ id: request[ParameterId].getInt,
+ powerState: intToBool(request[ParameterPowerState].getInt),
+ dimmerValue: request[ParameterDimmerValue].getInt,
+ sceneId: request[ParameterSceneId].getInt,
+ devices: devices
)
diff --git a/test.nim b/listGroups.nim
index 05a05cd..0975b9d 100644
--- a/test.nim
+++ b/listGroups.nim
@@ -8,4 +8,6 @@ let tradfriGateway = newTradfriGateway(
pass = "JrSGx6WkAVJUl53b"
)
-echo tradfriGateway.getGroups()
+let groups = %* tradfriGateway.getGroups()
+
+echo pretty groups
diff --git a/mappings.nim b/mappings.nim
index 8851506..4317347 100644
--- a/mappings.nim
+++ b/mappings.nim
@@ -17,12 +17,13 @@ const DeviceBlind* = "15015"
const ParameterName* = "9001"
const ParameterCreatedAt* = "9002"
const ParameterId* = "9003"
+const ParameterDeviceIds* = "9018"
const ParameterAlive* = "9019"
const ParameterLastSeen* = "9020"
-const ParameterType* = "5750"
+const ParameterSceneId* = "9039"
-const ParameterPowerState* = "5850"
-const ParameterDimmerValue* = "5851"
+const ParameterBlindTrigger* = "5523"
+const ParameterBlindPosition* = "5536"
const ParameterColorHex* = "5706"
const ParameterHue* = "5707"
@@ -31,9 +32,10 @@ const ParameterColorX* = "5709"
const ParameterColorY* = "5710"
const ParameterColorTemperature* = "5711"
const ParameterTransitionTime* = "5712"
+const ParameterType* = "5750"
-const ParameterBlindTrigger* = "5523"
-const ParameterBlindPosition* = "5536"
+const ParameterPowerState* = "5850"
+const ParameterDimmerValue* = "5851"
const ParameterGatewayNtpServerUrl* = "9023"
const ParameterGatewayVersion* = "9029"