github.com/stampzilla/stampzilla-go@v2.0.0-rc9+incompatible/nodes/stampzilla-knx/setup.go (about) 1 package main 2 3 import ( 4 "github.com/stampzilla/stampzilla-go/nodes/stampzilla-server/models/devices" 5 "github.com/stampzilla/stampzilla-go/pkg/node" 6 ) 7 8 func setupLight(node *node.Node, tunnel *tunnel, light light) { 9 traits := []string{} 10 11 if light.ControlSwitch != "" { 12 traits = append(traits, "OnOff") 13 } 14 if light.ControlBrightness != "" { 15 traits = append(traits, "Brightness") 16 } 17 18 dev := &devices.Device{ 19 Name: light.ID, 20 ID: devices.ID{ID: "light." + light.ID}, 21 Traits: traits, 22 State: devices.State{ 23 "on": false, 24 }, 25 } 26 27 if light.StateSwitch != "" { 28 tunnel.AddLink(light.StateSwitch, "on", "bool", dev) 29 } 30 31 if light.StateBrightness != "" { 32 tunnel.AddLink(light.StateBrightness, "brightness", "level", dev) 33 } 34 35 node.AddOrUpdate(dev) 36 } 37 func setupSensor(node *node.Node, tunnel *tunnel, sensor sensor) { 38 dev := &devices.Device{ 39 Name: sensor.ID, 40 ID: devices.ID{ID: "sensor." + sensor.ID}, 41 State: make(devices.State), 42 } 43 44 if sensor.Temperature != "" { 45 tunnel.AddLink(sensor.Temperature, "temperature", "temperature", dev) 46 } 47 if sensor.Motion != "" { 48 tunnel.AddLink(sensor.Motion, "motion", "bool", dev) 49 } 50 if sensor.Lux != "" { 51 tunnel.AddLink(sensor.Lux, "lux", "lux", dev) 52 } 53 if sensor.Humidity != "" { 54 tunnel.AddLink(sensor.Humidity, "humidity", "humidity", dev) 55 } 56 57 node.AddOrUpdate(dev) 58 }