summaryrefslogtreecommitdiffstats
path: root/deviceHelpers.nim
blob: c138d0d422e65846265c05ab8cdc1eb4e42bb81a (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
42
43
44
45
46
47
48
49
50
51
52
53
import types, helpers, tradfri

proc setPowerState* (device: TradfriDevice, state: bool): bool =
  if device.`type` == Lightbulb:
    return device.operateDevice(TradfriDeviceAction(
      kind:            LightSetPowerState,
      lightPowerState: state
    ))

  if device.`type` == Plug:
    return device.operateDevice(TradfriDeviceAction(
      kind:           PlugSetPowerState,
      plugPowerState: state
    ))
  

proc togglePowerState* (device: TradfriDevice): bool =
  var state: bool

  if device.`type` == Lightbulb:
    return device.operateDevice(TradfriDeviceAction(
      kind: LightSetPowerState,
      lightPowerState: invertBool(device.state.lightPowered)
    ))

  if device.`type` == Plug:
    return device.operateDevice(TradfriDeviceAction(
      kind: PlugSetPowerState,
      plugPowerState: invertBool(device.state.plugPowered)
    ))


proc setBrightness* (device: TradfriDevice, brightness: int): bool =
  return device.operateDevice(TradfriDeviceAction(
      kind: LightSetBrightness,
      lightBrightness: brightness
  ))


proc setColorHex* (device: TradfriDevice, color: string): bool =
  return device.operateDevice(TradfriDeviceAction(
      kind: LightSetColorHex,
      lightColorHex: color
  ))


proc setColorXY* (device: TradfriDevice, colorX: int, colorY: int): bool =
  return device.operateDevice(TradfriDeviceAction(
      kind: LightSetColorXY,
      lightColorX: colorX,
      lightColorY: colorY
  ))