Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
f2f16c811a
|
@ -7,7 +7,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"encoding/json"
|
|
||||||
"udi/database"
|
"udi/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -22,9 +21,9 @@ type hottisThreeWayThermometerValues struct {
|
|||||||
Value3 int32
|
Value3 int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSensorName(sensorsMap *map[string]string, sensorAddress uint64) string {
|
func getSensorName(sensorsMap *map[string]interface{}, sensorAddress uint64) string {
|
||||||
key := strconv.FormatUint(sensorAddress, 10)
|
key := strconv.FormatUint(sensorAddress, 10)
|
||||||
if sensorName, exists := (*sensorsMap)[key]; exists {
|
if sensorName, exists := (*sensorsMap)[key].(string); exists {
|
||||||
return sensorName
|
return sensorName
|
||||||
}
|
}
|
||||||
return "Sensor" + key
|
return "Sensor" + key
|
||||||
@ -32,15 +31,7 @@ func getSensorName(sensorsMap *map[string]string, sensorAddress uint64) string {
|
|||||||
|
|
||||||
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
|
func Parse(fPort int, _ []byte, frmPayload string, variables *map[string]database.VariableType, attributes *map[string]interface{}, device *database.Device) error {
|
||||||
deviceAttrs := (*device).Attributes
|
deviceAttrs := (*device).Attributes
|
||||||
sensorsMap := make(map[string]string)
|
sensorsMap := deviceAttrs["Sensors"].(map[string]interface{})
|
||||||
sensorsJSON, ok := deviceAttrs["Sensors"].(string)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("Unable to load sensor map from attributes")
|
|
||||||
}
|
|
||||||
errJ := json.Unmarshal([]byte(sensorsJSON), &sensorsMap)
|
|
||||||
if errJ != nil {
|
|
||||||
return fmt.Errorf("Unable to parse sensor map: %v", errJ)
|
|
||||||
}
|
|
||||||
|
|
||||||
if fPort != 2 {
|
if fPort != 2 {
|
||||||
return fmt.Errorf("Unexpected fPort %d", fPort)
|
return fmt.Errorf("Unexpected fPort %d", fPort)
|
||||||
|
Reference in New Issue
Block a user