-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathBatchChannel.go
45 lines (33 loc) · 991 Bytes
/
BatchChannel.go
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
package main
import "github.com/ninjasphere/go-ninja/devices"
type BatchChannel struct {
Channel
onOff *OnOffChannel
brightness *BrightnessChannel
color *ColorChannel
}
func (c *BatchChannel) init() error {
log.Debugf("Initialising batch channel of device %d", *c.device.deviceInfo.IeeeAddress)
err := c.device.driver.Conn.ExportChannel(c.device, c, c.ID)
if err != nil {
log.Fatalf("Failed to announce batch channel: %s", err)
}
return nil
}
func (c *BatchChannel) SetBatch(state *devices.LightDeviceState) error {
if c.onOff != nil && state.OnOff != nil {
c.onOff.SetOnOff(*state.OnOff)
}
if c.brightness != nil && state.Brightness != nil {
c.brightness.SetBrightness(*state.Brightness)
}
if c.color != nil && state.Color != nil {
c.color.SetColor(state.Color)
}
return nil
}
func (c *BatchChannel) GetProtocol() string {
return "core/batching"
}
func (c *BatchChannel) SetEventHandler(_ func(event string, payload ...interface{}) error) {
}