This repository has been archived by the owner on Feb 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
71 lines (58 loc) · 1.5 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
71
package main
import (
"context"
log "golang.org/x/exp/slog"
"os"
"os/signal"
"syscall"
"github.com/brutella/hap"
"github.com/brutella/hap/accessory"
)
var app_version string
var app_build string
var services []SystemDService
func init() {
if len(app_version) == 0 {
app_version = "dev"
}
}
func main() {
log.Info("Starting Go HomeKit Services Bridge", "version", app_version, "build", app_build)
bridge := SetupBridge()
log.Debug("Loading the accessories...")
svcsA := []*accessory.A{}
services = []SystemDService{}
for _, svc := range conf.Services {
services = append(services, svc.Init())
svcsA = append(svcsA, svc.Accessory.A)
}
log.Debug("Setting up the server...")
// Create the hap server.
fs := hap.NewFsStore(conf.DatabasePath)
server, err := hap.NewServer(fs, bridge.A, svcsA...)
if err != nil {
// stop if an error happens
log.Error("Error setting HomeKit Server", "error", err)
}
log.Info("Updating HomeKit Pairing PIN", "code", conf.PairingCode)
server.Pin = conf.PairingCode
// Setup a listener for interrupts and SIGTERM signals
// to stop the server.
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-c
// Stop delivering signals.
signal.Stop(c)
// Cancel the context to stop the server.
cancel()
}()
// Run the update Ticker
t := StartSystemDCheckTicker()
defer t.Stop()
// Run the server.
log.Info("Ready")
server.ListenAndServe(ctx)
}