This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
package prepared
|
||||
|
||||
import (
|
||||
"time"
|
||||
"log"
|
||||
"encoding/json"
|
||||
"log"
|
||||
"time"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
"udi/database"
|
||||
"udi/handlers/handler"
|
||||
)
|
||||
|
||||
|
||||
type PreparedHandler struct {
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
@@ -18,7 +17,7 @@ type PreparedHandler struct {
|
||||
type endpoint_t struct {
|
||||
Label string `json:"label"`
|
||||
Variable string `json:"variable"`
|
||||
Value string `json:"value"`
|
||||
Value interface{} `json:"value"`
|
||||
Unit string `json:"unit"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
@@ -29,10 +28,8 @@ type observation_t struct {
|
||||
Variables map[string]endpoint_t `json:"variables"`
|
||||
}
|
||||
|
||||
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &PreparedHandler {
|
||||
}
|
||||
t := &PreparedHandler{}
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
log.Printf("Handler Prepared %d initialized", id)
|
||||
@@ -55,13 +52,13 @@ func (self *PreparedHandler) Handle(message handler.MessageT) {
|
||||
measurement.Application = self.Id
|
||||
measurement.Device = observation.Device
|
||||
|
||||
measurement.Attributes = map[string]interface{} {
|
||||
measurement.Attributes = map[string]interface{}{
|
||||
"Label": observation.Label,
|
||||
}
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
for k, v := range observation.Variables {
|
||||
measurement.Values[k] = database.VariableType {
|
||||
measurement.Values[k] = database.VariableType{
|
||||
Label: v.Label,
|
||||
Variable: v.Variable,
|
||||
Unit: v.Unit,
|
||||
@@ -75,5 +72,3 @@ func (self *PreparedHandler) Handle(message handler.MessageT) {
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user