forked from llun/soundtouch-golang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.go
56 lines (49 loc) · 1.75 KB
/
info.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
package soundtouch
import (
"encoding/xml"
"fmt"
log "github.com/sirupsen/logrus"
)
// Info defines the Info command for the soundtouch system
type Info struct {
DeviceID string `xml:"deviceID,attr" json:",omitempty"`
Name string `xml:"name" json:",omitempty"`
Type string `xml:"type" json:",omitempty"`
IPAddress []string `xml:"networkInfo>ipAddress"`
Component []Component `xml:"components>component" json:",omitempty"`
MargeUrl string `xml:"margeURL" json:",omitempty"`
ModuleType string `xml:"moduleType" json:",omitempty"`
Variant string `xml:"variant" json:",omitempty"`
VariantMode string `xml:"variantMode" json:",omitempty"`
CountryCode string `xml:"countryCode" json:",omitempty"`
RegionCode string `xml:"regionCode" json:",omitempty"`
Raw []byte `json:"-"`
}
// Component contains some component information
type Component struct {
ComponentCategory string `xml:"componentCategory" json:",omitempty"`
SoftwareVersion string `xml:"softwareVersion" json:",omitempty"`
SerialNumber string `xml:"serialNumber" json:",omitempty"`
}
// Info retrieves speaker information and updates the speakers info field
func (s *Speaker) Info() (Info, error) {
body, err := s.GetData("info")
if err != nil {
return Info{}, err
}
info := Info{
Raw: body,
}
err = xml.Unmarshal(body, &info)
if err != nil {
return info, err
}
return info, nil
}
// String creates, depending of the loglevel different string representations on info message
func (s Info) String() string {
if log.GetLevel() >= log.TraceLevel {
return fmt.Sprintf("%v (%v): %v\n%v", s.Name, s.DeviceID, s.Type, string(s.Raw))
}
return fmt.Sprintf("%v (%v): %v", s.Name, s.DeviceID, s.Type)
}