summaryrefslogblamecommitdiffstats
path: root/gateway.nim
blob: d873a4cb119ad88150261a80a5416038f5456dbf (plain) (tree)







































                                                                                                                                         
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,
  )