This commit is contained in:
@@ -74,12 +74,22 @@ func (self *Mbgw3Handler) Handle(message handler.MessageT) {
|
||||
|
||||
measurement.Values = make(map[string]database.VariableType)
|
||||
unitMap := map[string]string { "Energy": "Wh", "Power": "W", "Voltage": "V", "Current": "A", "Volume": "m3" }
|
||||
keyCount := make(map[string]int)
|
||||
|
||||
for k, v := range observation.Values {
|
||||
unit, exists := unitMap[k]
|
||||
if ! exists {
|
||||
unit = "Unmapped Unit"
|
||||
}
|
||||
measurement.Values[k] = database.VariableType {
|
||||
|
||||
// Check if key already exists and create unique key if needed
|
||||
keyCount[k]++
|
||||
uniqueKey := k
|
||||
if keyCount[k] > 1 {
|
||||
uniqueKey = k + strconv.Itoa(keyCount[k])
|
||||
}
|
||||
|
||||
measurement.Values[uniqueKey] = database.VariableType {
|
||||
Label: "",
|
||||
Variable: k,
|
||||
Unit: unit,
|
||||
|
||||
Reference in New Issue
Block a user