Cloud Export example transform always error with "Unexpected type received"
lenny-goodell opened this issue Β· comments
Lenny Goodell commented
π Bug Report
Affected Services [REQUIRED]
The issue is located in: application-services/custom/cloud-export-mqttIs this a regression? Yes, since conversion to 2.x
Description and Minimal Reproduction [REQUIRED]
Problem is the transform is using the models
package rather than the dtos
package and get an error when it check the type of the Event received.
Code for the transform should be:
if data == nil {
return false, errors.New("No Event Received")
}
ctx.LoggingClient().Debug("Transforming to AWS format")
if event, ok := data.(dtos.Event); ok {
readings := map[string]interface{}{}
for _, reading := range event.Readings {
switch reading.ValueType {
case common.ValueTypeBinary:
readings[reading.ResourceName] = reading.BinaryValue
case common.ValueTypeObject:
readings[reading.ResourceName] = reading.ObjectValue
default:
readings[reading.ResourceName] = reading.Value
}
}
msg, err := json.Marshal(readings)
if err != nil {
return false, errors.New(fmt.Sprintf("Failed to transform AWS data: %s", err))
}
return true, string(msg)
}
return false, errors.New("Unexpected type received")
π₯ Exception or Error
Unexpected type received
π Your Environment
N/A