forked from llun/soundtouch-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvolume.go
42 lines (37 loc) · 931 Bytes
/
volume.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
package soundtouch
import (
"encoding/xml"
"fmt"
)
// Volume defines the Volume command
type Volume struct {
DeviceID string `xml:"deviceID,attr"`
TargetVolume int `xml:"targetvolume"`
ActualVolume int `xml:"actualvolume"`
Muted bool `xml:"mutedenabled"`
Raw []byte `json:"-"`
}
// Volume sends the volume command to the soundtouch system to retrieve the volume
func (s *Speaker) Volume() (Volume, error) {
body, err := s.GetData("volume")
if err != nil {
return Volume{}, err
}
volume := Volume{
Raw: body,
}
err = xml.Unmarshal(body, &volume)
if err != nil {
return volume, err
}
return volume, nil
}
// SetVolume sends the volume command to the soundtouch system to set the volume
func (s *Speaker) SetVolume(volume int) error {
data := []byte(fmt.Sprintf("<volume>%v</volume>", volume))
_, err := s.SetData("volume", data)
if err != nil {
return err
}
return nil
}