-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththings.go
88 lines (75 loc) · 2.52 KB
/
things.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
package restapi
import "time"
// Thing describes a third party device or service
type Thing struct {
ID string `json:"id"`
Name string `json:"name"`
Manufacturer string `json:"manufacturer"`
DisplayType string `json:"displayType"`
MainComponentID string `json:"mainComponentId"`
Status StatusType `json:"status"`
Components []Component `json:"components"`
Attributes []ThingAttribute `json:"attributes,omitempty"`
}
// ThingAttribute defines a key value pair that can be stored within a thing
type ThingAttribute struct {
Name string `json:"name"`
Value string `json:"value"`
}
// StatusType defines thing status
type StatusType string
// Component is part of a thing
type Component struct {
ID string `json:"id"`
Name string `json:"name"`
ComponentType string `json:"componentType"`
Capabilities []string `json:"capabilities"`
Properties []Property `json:"properties,omitempty"`
Actions []Action `json:"actions,omitempty"`
}
// Property is part of a thing component
type Property struct {
ID string `json:"id"`
Name string `json:"name"`
Value string `json:"value"`
Unit string `json:"unit"`
Type ValueType `json:"type"`
LastUpdate time.Time `json:"lastUpdate"`
PropertyType string `json:"propertyType"`
}
// ValueType defines the type of a value
type ValueType string
// Action is part of a thing component
type Action struct {
ID string `json:"id"`
Name string `json:"name"`
Parameters []ActionParameter `json:"parameters,omitempty"`
}
// ActionParameter define which parameters a thing action requires
type ActionParameter struct {
Name string `json:"name"`
Type ValueType `json:"type"`
}
// definition of value and status types
const (
ValueTypeNumber = ValueType("NUMBER")
ValueTypeString = ValueType("STRING")
ValueTypeBoolean = ValueType("BOOLEAN")
StatusTypeUnknown = StatusType("UNKNOWN")
StatusTypeAvailable = StatusType("AVAILABLE")
StatusTypeUnavailable = StatusType("UNAVAILABLE")
)
var (
// AllValueTypes declares list of possbile value types
AllValueTypes = map[ValueType]struct{}{
ValueTypeNumber: {},
ValueTypeString: {},
ValueTypeBoolean: {},
}
// AllStatusTypes defines list of possible status types
AllStatusTypes = map[StatusType]struct{}{
StatusTypeUnknown: {},
StatusTypeAvailable: {},
StatusTypeUnavailable: {},
}
)