-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclu.go
75 lines (63 loc) · 1.24 KB
/
clu.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"fmt"
"strconv"
"strings"
"sync"
"github.com/brutella/hc/accessory"
)
type Clu struct {
Id string
Name string
Lights []*Light
Therms []*Thermo
Shutters []*Shutter
SimpleShutters []*ShutterSimple
set *GrentonSet
block sync.Mutex
}
func (gc *Clu) GetIntId() uint32 {
cluIdS := gc.Id[3:]
var base int
if strings.HasPrefix(cluIdS, "_") {
base = 16
} else {
base = 10
}
uVal, err := strconv.ParseUint(cluIdS[1:], base, 32)
if err != nil {
err = fmt.Errorf("Converting clu id [%s] (to uint) failed: %v", gc.Id, err)
gc.set.Error(err)
}
return uint32(uVal)
}
func (gc *Clu) GetMixedId() string {
return gc.Id
}
func (gc *Clu) InitAll() {
for _, light := range gc.Lights {
light.clu = gc
light.InitAll()
}
for _, thermo := range gc.Therms {
thermo.clu = gc
thermo.InitAll()
}
for _, sht := range gc.SimpleShutters {
sht.clu = gc
sht.InitAll()
}
}
func (gc *Clu) GetAllHkAcc() (slc []*accessory.Accessory) {
slc = []*accessory.Accessory{}
for _, light := range gc.Lights {
slc = append(slc, light.hk.Accessory)
}
for _, thermo := range gc.Therms {
slc = append(slc, thermo.hk.Accessory)
}
for _, sht := range gc.SimpleShutters {
slc = append(slc, sht.hk.Accessory)
}
return
}