This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
forked from gozwave/gozw
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
70 lines (57 loc) · 1.88 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"github.com/davecgh/go-spew/spew"
"github.com/gozwave/gozw"
)
var networkKey = []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
func main() {
devicePath := "/dev/tty.usbmodem141101"
if p := os.Getenv("GOZW_DEVICE_PATH"); p != "" {
devicePath = p
}
fmt.Println("Adding the same node twice will update the network appropriately, but the client will keep duplicate entries of the nodes in its internal map. PruneNodes removes the node from the client's internal map and DB")
client, err := gozw.NewDefaultClient("/tmp/data.db", devicePath, 115200, networkKey)
if err != nil {
log.Fatal(err)
}
defer func() {
if err := client.Shutdown(); err != nil {
log.Fatal(err)
}
}()
spew.Dump(client.Controller)
for _, node := range client.Nodes() {
fmt.Println(node.String())
}
fmt.Println("removing node, put device in unpairing mode")
if _, err := client.RemoveNode(); err != nil {
log.Fatalf("failed to remove node: %v", err)
}
fmt.Println("-----------------------------------------")
fmt.Println("adding node, put device in pairing mode")
_, err = client.AddNode()
if err != nil {
log.Fatalf("failed to add node: %v", err)
}
fmt.Printf("%+v", client.Nodes())
client.PruneNodes()
fmt.Printf("%+v", client.Nodes())
fmt.Println("=========================================")
fmt.Println("removing node, put device in unpairing mode")
if _, err = client.RemoveNode(); err != nil {
log.Fatalf("failed to remove node: %v", err)
}
fmt.Println("-----------------------------------------")
fmt.Println("adding node, put device in pairing mode")
_, err = client.AddNode()
if err != nil {
log.Fatalf("failed to add node: %v", err)
}
fmt.Printf("%+v", client.Nodes())
client.PruneNodes()
fmt.Printf("%+v", client.Nodes())
fmt.Println("=========================================")
}