/
types.go
62 lines (59 loc) · 1.76 KB
/
types.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
package entities
import "encoding/json"
// //////////////////////////////////////////////////////////////////////////////
// Do not modify this file, it is automatically generated
// //////////////////////////////////////////////////////////////////////////////
type Entity interface {
GetRawId() string
GetUniqueId() string
GetDomainEntity() string
GetName() string
PopulateDevice(Manufacturer string, SoftwareName string, InstanceName string, SWVersion string, Identifier string)
UpdateState()
Subscribe()
UnSubscribe()
AddMessageHandler()
DeleteTopic()
Initialize()
SetMQTTFields(MQTTFields)
GetMQTTFields() MQTTFields
}
type Device struct {
ConfigurationUrl *string `json:"configuration_url,omitempty"`
Connections *string `json:"connections,omitempty"`
Identifiers *string `json:"identifiers,omitempty"`
Manufacturer *string `json:"manufacturer,omitempty"`
Model *string `json:"model,omitempty"`
Name *string `json:"name,omitempty"`
SuggestedArea *string `json:"suggested_area,omitempty"`
SwVersion *string `json:"sw_version,omitempty"`
ViaDevice *string `json:"via_device,omitempty"`
}
type Topic struct {
Topic string `json:"topic"`
ValueTemplate *string `json:"value_template"`
}
func (t Topic) MarshalJSON() ([]byte, error) {
if t.ValueTemplate == nil {
return json.Marshal(t.Topic)
}
return json.Marshal(struct {
Topic string `json:"topic"`
ValueTemplate *string `json:"value_template"`
}{
Topic: t.Topic,
ValueTemplate: t.ValueTemplate,
})
}
func NewTopic(topic string, valueTemplate string) Topic {
if valueTemplate == "" {
return Topic{
Topic: topic,
ValueTemplate: nil,
}
}
return Topic{
Topic: topic,
ValueTemplate: &valueTemplate,
}
}