@@ -33,22 +33,25 @@ type Trigger struct {
33
33
Command Command `json:"command"`
34
34
}
35
35
36
- type Sensor struct {
37
- Name string `json:"name"`
36
+ type GeneralSensor struct {
38
37
ResultTopic string `json:"topic"`
39
38
Retained bool `json:"retained"`
40
39
Interval Interval `json:"interval"`
41
- Unit string `json:"unit"`
42
- Icon string `json:"icon"`
43
40
Command Command `json:"command"`
44
41
}
45
42
43
+ type Sensor struct {
44
+ GeneralSensor
45
+
46
+ Name string `json:"name"`
47
+ Unit string `json:"unit"`
48
+ Icon string `json:"icon"`
49
+ }
50
+
46
51
type MultiSensor struct {
47
- ResultTopic string `json:"topic"`
48
- Retained bool `json:"retained"`
49
- Interval Interval `json:"interval"`
50
- Command Command `json:"command"`
51
- Values []MultiSensorValue `json:"values"`
52
+ GeneralSensor
53
+
54
+ Values []MultiSensorValue `json:"values"`
52
55
}
53
56
54
57
type MultiSensorValue struct {
@@ -104,6 +107,17 @@ func LoadTopicConfiguration(configFilePath, deviceId string) (TopicConfiguration
104
107
return topicConfig , nil
105
108
}
106
109
110
+ func (t * TopicConfigurations ) Sensors () []GeneralSensor {
111
+ sensors := make ([]GeneralSensor , 0 , len (t .Sensor )+ len (t .MultiSensor ))
112
+ for _ , sensor := range t .Sensor {
113
+ sensors = append (sensors , sensor .GeneralSensor )
114
+ }
115
+ for _ , sensor := range t .MultiSensor {
116
+ sensors = append (sensors , sensor .GeneralSensor )
117
+ }
118
+ return sensors
119
+ }
120
+
107
121
func (t * TopicConfigurations ) validate () error {
108
122
if t .Availability != nil {
109
123
if err := checkTopicName (t .Availability .Topic ); err != nil {
0 commit comments