voltage hack
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful

This commit is contained in:
2025-12-22 18:50:59 +01:00
parent 3b69e1e2af
commit a78c6952f0
2 changed files with 15 additions and 9 deletions

View File

@@ -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,