-
Notifications
You must be signed in to change notification settings - Fork 1
/
viaset.go
91 lines (71 loc) · 2.14 KB
/
viaset.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package kramer
import (
"context"
"errors"
"fmt"
"strconv"
"strings"
)
// Set the Volume for a VIA
func (v *Via) SetViaVolume(ctx context.Context, volume int) (string, error) {
var cmd command
cmd.Command = "Vol"
cmd.Param1 = "Set"
cmd.Param2 = strconv.Itoa(volume)
v.Debugf("Sending volume set command to %s", v.Address)
resp, err := v.sendCommand(ctx, cmd)
if err != nil {
return "", errors.New(fmt.Sprintf("Error in setting volume on %s", v.Address))
}
return resp, nil
}
// Reboot: Reboot a VIA using the API
func (v *Via) Reboot(ctx context.Context) error {
var cmd command
cmd.Command = viaReboot
v.Infof("Sending command %s to %s", viaReboot, v.Address)
_, err := v.sendCommand(ctx, cmd)
if err != nil {
return err
}
return nil
}
// Reset: Reset a VIA sessions - Causes VIAAdmin to log out and log back in which can help with some lock up issues.
func (v *Via) Reset(ctx context.Context) error {
var cmd command
cmd.Command = viaReset
v.Infof("Sending command %s to %s", viaReset, v.Address)
resp, err := v.sendCommand(ctx, cmd)
if err != nil {
return err
}
if strings.Contains(resp, viaReset) && strings.Contains(resp, "1") {
return nil
}
return errors.New(fmt.Sprintf("Incorrect response for command. (Response: %s)", resp))
}
// SetAlert - Send an alert popup on the screen of the VIA
func (v *Via) SetAlert(ctx context.Context, AlertMessage string) error {
v.Debugf("AlertMessage to pass: %s", AlertMessage)
var cmd command
cmd.Command = "IAlert"
cmd.Param1 = AlertMessage
cmd.Param2 = "0"
cmd.Param3 = "5"
v.Infof("Sending Alert to %v", v.Address)
v.Debugf("Sending an alert message -%s- to %s", AlertMessage, v.Address)
resp, err := v.sendCommand(ctx, cmd)
if err != nil {
v.Errorf("Error in setting alert on %s", v.Address)
return fmt.Errorf("Error in setting alert on %s", v.Address)
}
clean := strings.TrimRight(resp, "\r\n")
sp := strings.Split(clean, "|")
s := sp[1]
sint, err := strconv.Atoi(s)
if sint != 1 {
v.Errorf("Alert was not successfully sent, check settings and try again")
return fmt.Errorf("Alert was not successfully sent, checking settings and try again")
}
return nil
}