-
Notifications
You must be signed in to change notification settings - Fork 2
/
persistence.go
47 lines (36 loc) · 1.39 KB
/
persistence.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
package zda
import (
"github.com/shimmeringbee/persistence"
"github.com/shimmeringbee/zigbee"
"strconv"
)
func (z *ZDA) sectionRemoveNode(i zigbee.IEEEAddress) bool {
return z.section.Section("Node").SectionDelete(i.String())
}
func (z *ZDA) sectionForNode(i zigbee.IEEEAddress) persistence.Section {
return z.section.Section("Node", i.String())
}
func (z *ZDA) nodeListFromPersistence() []zigbee.IEEEAddress {
var nodeList []zigbee.IEEEAddress
for _, k := range z.section.Section("Node").SectionKeys() {
if addr, err := strconv.ParseUint(k, 16, 64); err == nil {
nodeList = append(nodeList, zigbee.IEEEAddress(addr))
}
}
return nodeList
}
func (z *ZDA) sectionRemoveDevice(i IEEEAddressWithSubIdentifier) bool {
return z.sectionForNode(i.IEEEAddress).Section("Device").SectionDelete(strconv.Itoa(int(i.SubIdentifier)))
}
func (z *ZDA) sectionForDevice(i IEEEAddressWithSubIdentifier) persistence.Section {
return z.sectionForNode(i.IEEEAddress).Section("Device", strconv.Itoa(int(i.SubIdentifier)))
}
func (z *ZDA) deviceListFromPersistence(id zigbee.IEEEAddress) []IEEEAddressWithSubIdentifier {
var deviceList []IEEEAddressWithSubIdentifier
for _, k := range z.sectionForNode(id).Section("Device").SectionKeys() {
if i, err := strconv.Atoi(k); err == nil {
deviceList = append(deviceList, IEEEAddressWithSubIdentifier{IEEEAddress: id, SubIdentifier: uint8(i)})
}
}
return deviceList
}