-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcallbacks.go
More file actions
111 lines (96 loc) · 2.98 KB
/
Copy pathcallbacks.go
File metadata and controls
111 lines (96 loc) · 2.98 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package main
import (
"arcam-controller/arcam"
"context"
"net/http"
"github.com/brutella/hap/characteristic"
"github.com/brutella/hap/log"
)
func requestCurrentSourceCallback(receiver *HomekitReceiver) func(arcam.ZoneNumber, []byte) error {
return func(zone arcam.ZoneNumber, data []byte) error {
return receiver.SetSource(int(data[0]))
}
}
func powerCommandCallback(receiver *HomekitReceiver) func(arcam.ZoneNumber, []byte) error {
return func(zone arcam.ZoneNumber, data []byte) error {
active := characteristic.ActiveInactive
if arcam.PowerStatus(data[0]) == arcam.PowerStatusActive {
active = characteristic.ActiveActive
}
return receiver.SetPowerState(active)
}
}
func muteCommandCallback(receiver *HomekitReceiver) func(arcam.ZoneNumber, []byte) error {
return func(zone arcam.ZoneNumber, data []byte) error {
isMuted := arcam.MuteState(data[0]) == arcam.MuteStateMuted
receiver.SetMute(isMuted)
return nil
}
}
func directModeCommandCallback(receiver *HomekitReceiver) func(arcam.ZoneNumber, []byte) error {
return func(zone arcam.ZoneNumber, data []byte) error {
enable := arcam.DirectModeStatus(data[0]) == arcam.DirectModeActive
return receiver.SetDirectMode(enable)
}
}
func volumeCommandCallback(receiver *HomekitReceiver) func(arcam.ZoneNumber, []byte) error {
return func(zone arcam.ZoneNumber, data []byte) error {
return receiver.SetVolume(int(data[0]))
}
}
func directModeStatusCallback(ctx context.Context, arcamClient arcam.Receiver) boolCallback {
return func(newVal, oldVal bool, r *http.Request) {
var err error
if newVal {
err = arcamClient.EnableDirectMode(ctx)
} else {
err = arcamClient.DisableDirectMode(ctx)
}
if err != nil {
log.Info.Fatalln("")
}
}
}
func muteCallback(ctx context.Context, arcamClient arcam.Receiver) boolCallback {
return func(newVal, oldVal bool, r *http.Request) {
var err error
if newVal {
err = arcamClient.Mute(ctx)
} else {
err = arcamClient.UnMute(ctx)
}
if err != nil {
log.Info.Fatalln("")
}
}
}
func volumeCallback(ctx context.Context, arcamClient arcam.Receiver) intCallback {
return func(newVal, oldVal int, r *http.Request) {
err := arcamClient.SetVolume(ctx, newVal)
if err != nil {
log.Info.Fatalln("")
}
}
}
func powerCallback(ctx context.Context, arcamClient arcam.Receiver) intCallback {
return func(newVal, oldVal int, r *http.Request) {
if newVal == characteristic.ActiveActive {
err := arcamClient.PowerOn(ctx)
if err != nil {
log.Info.Fatalln("")
}
return
}
err := arcamClient.PowerOff(ctx)
if err != nil {
log.Info.Fatalln("")
}
}
}
func sourceCallback(ctx context.Context, arcamClient arcam.Receiver) intCallback {
return func(newVal, oldVal int, r *http.Request) {
// TODO: should have some logic here that if we are going with the analog input (record player) we should
// do stereo analog pass through, maybe make it an option to the plugin if this is what you want to do
arcamClient.SetSource(ctx, arcam.InputSource(newVal))
}
}