status-lib/status/devices.nim

44 lines
1.4 KiB
Nim
Raw Permalink Normal View History

2021-09-08 18:05:39 +00:00
import system
import statusgo_backend/settings
2021-09-08 18:05:39 +00:00
import types/[setting, installation]
import statusgo_backend/installations
2021-09-08 18:05:39 +00:00
import json
proc setDeviceName*(name: string) =
discard setInstallationMetadata(getSetting[string](Setting.InstallationId, "", true), name, hostOs)
proc isDeviceSetup*():bool =
let installationId = getSetting[string](Setting.InstallationId, "", true)
let responseResult = getOurInstallations()
if responseResult.kind == JNull:
return false
for installation in responseResult:
if installation["id"].getStr == installationId:
return installation["metadata"].kind != JNull
result = false
proc syncAllDevices*() =
let preferredUsername = getSetting[string](Setting.PreferredUsername, "")
discard syncDevices(preferredUsername)
proc advertise*() =
discard sendPairInstallation()
proc getAllDevices*():seq[Installation] =
let responseResult = getOurInstallations()
let installationId = getSetting[string](Setting.InstallationId, "", true)
result = @[]
if responseResult.kind != JNull:
for inst in responseResult:
var device = inst.toInstallation
if device.installationId == installationId:
device.isUserDevice = true
result.add(device)
proc enable*(installationId: string) =
# TODO handle errors
discard enableInstallation(installationId)
proc disable*(installationId: string) =
discard disableInstallation(installationId)