Compare commits

..

6 Commits

Author SHA1 Message Date
f2f16c811a still sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:50:54 +02:00
6f9327fdd6 sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:36:17 +02:00
1d1942a4d3 sensor labels 2024-07-31 16:26:51 +02:00
d6e7fa3949 sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:22:39 +02:00
97c6a045d2 sensor labels
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/tag/woodpecker Pipeline was successful
2024-07-31 16:14:29 +02:00
f10f9afd8b sensor labels
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2024-07-31 16:10:52 +02:00

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"fmt" "fmt"
"bytes" "bytes"
"strconv"
"encoding/base64" "encoding/base64"
"encoding/binary" "encoding/binary"
"udi/database" "udi/database"
@ -20,8 +21,18 @@ type hottisThreeWayThermometerValues struct {
Value3 int32 Value3 int32
} }
func getSensorName(sensorsMap *map[string]interface{}, sensorAddress uint64) string {
key := strconv.FormatUint(sensorAddress, 10)
if sensorName, exists := (*sensorsMap)[key].(string); exists {
return sensorName
}
return "Sensor" + key
}
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
deviceAttrs := (*device).Attributes
sensorsMap := deviceAttrs["Sensors"].(map[string]interface{})
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, _ *database.Device) error {
if fPort != 2 { if fPort != 2 {
return fmt.Errorf("Unexpected fPort %d", fPort) return fmt.Errorf("Unexpected fPort %d", fPort)
} }
@ -56,19 +67,19 @@ func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]databas
Value: battery, Value: battery,
} }
(*variables)["Temperature1"] = database.VariableType { (*variables)["Temperature1"] = database.VariableType {
Label: "Temperature1", Label: getSensorName(&sensorsMap, values.SensorAddress1),
Variable: "Temperature", Variable: "Temperature",
Unit: "°C", Unit: "°C",
Value: value1, Value: value1,
} }
(*variables)["Temperature2"] = database.VariableType { (*variables)["Temperature2"] = database.VariableType {
Label: "Temperature2", Label: getSensorName(&sensorsMap, values.SensorAddress2),
Variable: "Temperature", Variable: "Temperature",
Unit: "°C", Unit: "°C",
Value: value2, Value: value2,
} }
(*variables)["Temperature3"] = database.VariableType { (*variables)["Temperature3"] = database.VariableType {
Label: "Temperature3", Label: getSensorName(&sensorsMap, values.SensorAddress3),
Variable: "Temperature", Variable: "Temperature",
Unit: "°C", Unit: "°C",
Value: value3, Value: value3,