-
Notifications
You must be signed in to change notification settings - Fork 0
/
hkow.go
57 lines (46 loc) · 938 Bytes
/
hkow.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
package main
import (
"log"
"net"
"time"
"github.com/gradddev/hkmh"
"github.com/brutella/hc"
"github.com/brutella/hc/accessory"
)
func main() {
bridge := accessory.NewBridge(accessory.Info{Name: "Mi Router 3G", ID: 1})
deskLight := hkmh.NewAccessory(hkmh.Config{
ID: 2,
IP: net.ParseIP("192.168.1.211"),
Name: "Desk Light",
Timeout: 3 * time.Second,
})
bedLight := hkmh.NewAccessory(hkmh.Config{
ID: 3,
IP: net.ParseIP("192.168.1.215"),
Name: "Bed Light",
Timeout: 3 * time.Second,
})
storagePath := "/etc/.hkow"
log.Println(storagePath)
config := hc.Config{
StoragePath: storagePath,
Pin: "00207700",
}
t, err := hc.NewIPTransport(
config,
bridge.Accessory,
deskLight.Accessory,
bedLight.Accessory,
)
handleError(err)
hc.OnTermination(func() {
<-t.Stop()
})
t.Start()
}
func handleError(err error) {
if err != nil {
log.Panicln(err)
}
}