forked from llun/soundtouch-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsources.go
38 lines (33 loc) · 991 Bytes
/
sources.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
package soundtouch
import (
"encoding/xml"
)
// SourceItem defines a source within a soundtouch system
type SourceItem struct {
Source Source `xml:"source,attr" json:",omitempty"`
SourceAccount string `xml:"sourceAccount,attr" json:",omitempty"`
Status string `xml:"status,attr" json:",omitempty"`
Local bool `xml:"isLocal,attr" json:",omitempty"`
Value string `xml:",innerxml" json:",omitempty"`
}
// Sources defines the soundtouch sources command
type Sources struct {
DeviceID string `xml:"deviceID,attr" json:",omitempty"`
SourceItems []SourceItem `xml:"sourceItem"`
Raw []byte `json:"-"`
}
// Sources sends the sources command to the soundtouch system
func (s *Speaker) Sources() (Sources, error) {
body, err := s.GetData("sources")
if err != nil {
return Sources{}, err
}
sources := Sources{
Raw: body,
}
err = xml.Unmarshal(body, &sources)
if err != nil {
return sources, err
}
return sources, nil
}