ctucx.git: nimtradfri

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

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 
import json

import types, gatewayTypes
import mappings, helpers
import coapClient

proc newTradfrigateway* (host: string, port: int, user: string, pass: string): TradfriGatewayRef = 
  return TradfriGatewayRef(
      host: host,
      port: port,
      user: user,
      pass: pass
    )

proc getGatewayDetails* (gatewayRef: TradfriGatewayRef): TradfriGatewayDetails = 
  let request = makeCoapRequest(gatewayRef.host, gatewayRef.port, "get", gatewayRef.user, gatewayRef.pass, EndpointGatewayDetails, %* {})

  echo pretty request

  return TradfriGatewayDetails(
     alexaPaired:                  intToBool(request[ParameterGatewayAlexaPaired].getInt),
     googleHomePaired:             intToBool(request[ParameterGatewayAlexaPaired].getInt),
     currUnixTimestampUTC:         request[ParameterGatewayUtcNowUnixTimestamp].getInt,
     timeSource:                   request[ParameterGatewayTimeSource].getInt,
     ntpServer:                    request[ParameterGatewayNtpServerUrl].getStr,
     version:                      request[ParameterGatewayVersion].getStr,
     otaUpdateRunning:             intToBool(request[ParameterGatewayOtaUpdateState].getInt),
     otaUpdateProgress:            request[ParameterGatewayOtaUpdateProgress].getInt,
     otaUpdatePriority:            TradfriUpdatePriority(request[ParameterGatewayOtaUpdatePriority].getInt),
     otaUpdateAcceptedTimestamp:   request[ParameterGatewayOtaUpdateAcceptedTimestamp].getInt,
     dstStartMonth:                request[ParameterGatewayDstStartMonth].getInt,
     dstStartDay:                  request[ParameterGatewayDstStartDay].getInt,
     dstStartHour:                 request[ParameterGatewayDstStartHour].getInt,
     dstStartMinute:               request[ParameterGatewayDstStartMinute].getInt,
     dstEndMonth:                  request[ParameterGatewayDstEndMonth].getInt,
     dstEndDay:                    request[ParameterGatewayDstEndDay].getInt,
     dstEndHour:                   request[ParameterGatewayDstEndHour].getInt,
     dstEndMinute:                 request[ParameterGatewayDstEndMinute].getInt,
     dstTimeOffset:                request[ParameterGatewayDstTimeOffset].getInt,
  )