-
Notifications
You must be signed in to change notification settings - Fork 1
/
ringnotify.go
61 lines (55 loc) · 1.14 KB
/
ringnotify.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
package main
import (
"log"
"os"
"os/exec"
"strings"
"time"
)
type ringNotify struct {
statusLoop
}
func (l *ringNotify) ProcessEvent(ev MQTTEvent) []MQTTPublish {
if ev.Topic != "doorbell/events/ring" {
return nil // event did not influence our state
}
go func() {
if err := playSound(); err != nil {
log.Print(err)
}
}()
body := "<i>jetzt geklingelt (" + string(ev.Payload.([]byte)) + ")</li>"
icon := "/home/michael/zkj-workspace-switcher/bell-solid.png"
title := "Türklingel!"
dunstify := exec.Command(
"dunstify",
"--icon="+icon,
"--action=open,Open",
"--timeout=10000", // ms, i.e. 10 seconds
title,
body)
dunstify.Stderr = os.Stderr
b, err := dunstify.Output()
if err != nil {
l.statusf("%v", err)
return nil
}
result := strings.TrimSpace(string(b))
l.statusf("%v] ring notification shown", time.Now().Format(time.RFC3339Nano))
log.Printf("result=%q", result)
switch result {
case "1":
// timeout
case "2":
// dismissed
case "open":
log.Printf("open triggered, unlocking door")
return []MQTTPublish{
{
Topic: "doorbell/cmd/unlock",
Payload: "unlock",
},
}
}
return nil
}