@@ -17,15 +17,17 @@ package eliona
17
17
18
18
import (
19
19
"context"
20
- api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2"
21
- "github.com/eliona-smart-building-assistant/go-eliona/asset"
22
- "github.com/eliona-smart-building-assistant/go-utils/common"
23
- "github.com/eliona-smart-building-assistant/go-utils/log"
24
20
"hailo/apiserver"
25
21
"hailo/conf"
26
22
"hailo/hailo"
27
23
"math"
24
+ "strconv"
28
25
"time"
26
+
27
+ api "github.com/eliona-smart-building-assistant/go-eliona-api-client/v2"
28
+ "github.com/eliona-smart-building-assistant/go-eliona/asset"
29
+ "github.com/eliona-smart-building-assistant/go-utils/common"
30
+ "github.com/eliona-smart-building-assistant/go-utils/log"
29
31
)
30
32
31
33
func UpsertDataForDevices (config apiserver.Configuration , spec hailo.Spec ) error {
@@ -110,10 +112,10 @@ func UpsertDataForStation(config apiserver.Configuration, status hailo.Status) e
110
112
parseTime (status .Generic .LastContact ),
111
113
* assetId ,
112
114
stationDataPayload {
113
- int (status .DeviceTypeSpecific .AverageBatteryLevel * 100 ),
115
+ int (interfaceToFloat ( status .DeviceTypeSpecific .AverageBatteryLevel ) * 100 ),
114
116
lastContact ,
115
117
status .DeviceTypeSpecific .TotalInputsCount ,
116
- int (status .DeviceTypeSpecific .AverageFillingLevel * 100 ),
118
+ int (interfaceToFloat ( status .DeviceTypeSpecific .AverageFillingLevel ) * 100 ),
117
119
CheckActivity (config , lastContact ),
118
120
},
119
121
)
@@ -125,6 +127,22 @@ func UpsertDataForStation(config apiserver.Configuration, status hailo.Status) e
125
127
return nil
126
128
}
127
129
130
+ func interfaceToFloat (value interface {}) float64 {
131
+ var fValue float64 = - 1
132
+
133
+ switch v := value .(type ) {
134
+ case string :
135
+ fValue , _ = strconv .ParseFloat (v , 32 )
136
+ case int :
137
+ fValue = (float64 )(v )
138
+ case float32 :
139
+ fValue = (float64 )(v )
140
+ case float64 :
141
+ fValue = v
142
+ }
143
+ return fValue
144
+ }
145
+
128
146
func CheckActivity (connection apiserver.Configuration , lastContact float64 ) bool {
129
147
return lastContact < (float64 )(connection .InactiveTimeout / 3600 )
130
148
}
0 commit comments