-
Notifications
You must be signed in to change notification settings - Fork 0
/
devicedetails.go
47 lines (39 loc) · 1.45 KB
/
devicedetails.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
package local
import "encoding/xml"
//DeviceDetailsCommand gets all variables available
type DeviceDetailsCommand struct {
Command
DeviceDetails DeviceDetails
}
type DeviceDetailsResponse struct {
XMLName xml.Name `xml:"Device" json:"-"`
DeviceDetails DeviceDetails `json:"details"`
Components ComponentNames `json:"components"`
}
func NewDeviceDetailsCommand(hardwareAddress string) DeviceDetailsCommand {
return DeviceDetailsCommand{
Command: NewCommand("device_details"),
DeviceDetails: DeviceDetails{DeviceData: DeviceData{HardwareAddress: hardwareAddress}},
}
}
//VariablesFromDetailsResponse unwraps a DeviceDetailsResponse to get the list of Variable names
func VariablesFromDetailsResponse(response DeviceDetailsResponse) []string {
var variables []string
for _, component := range response.Components.Component {
for _, variable := range component.Variables.Variable {
variables = append(variables, variable)
}
}
return variables
}
//ResultsFromDetailsResponse returns a map of component name -> variable name -> Variable
func ResultsFromDetailsResponse(response DeviceQueryResponse) map[string]map[string]Variable {
variables := make(map[string]map[string]Variable)
for _, component := range response.Components.Component {
variables[component.Name] = make(map[string]Variable)
for _, variable := range component.Variables.Variable {
variables[component.Name][variable.Name] = variable
}
}
return variables
}