-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.go
53 lines (43 loc) · 1.07 KB
/
app.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
package main
import (
"os"
"time"
"github.com/ninjasphere/app-security-light/service"
"github.com/ninjasphere/go-ninja/api"
"github.com/ninjasphere/go-ninja/support"
)
var info = ninja.LoadModuleInfo("./package.json")
// This object is persisted by HomeCloud, and provided when the app starts.
type Config struct {
Lights []service.SecurityLightConfig `json:"lights"`
}
type App struct {
support.AppSupport
}
func (a *App) Start(config *Config) error {
return service.Start(config.Lights, a.Conn, func(config []service.SecurityLightConfig) {
a.SendEvent("config", Config{config})
})
}
// Stop the security light app.
func (a *App) Stop() error {
// Can't really stop at the moment, so just bomb out.
a.Log.Infof("Stop called. Quitting in 3 sec...")
go func() {
time.Sleep(time.Second * 3)
os.Exit(0)
}()
return nil
}
func main() {
app := &App{}
err := app.Init(info)
if err != nil {
app.Log.Fatalf("failed to initialize app: %v", err)
}
err = app.Export(app)
if err != nil {
app.Log.Fatalf("failed to export app: %v", err)
}
support.WaitUntilSignal()
}