Skip to content

Commit

Permalink
fix: add check for nil for property value
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjagad committed Sep 17, 2024
1 parent 9d7aa13 commit 56d5f78
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pkg/framer/property_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ func (p AssetPropertyValue) Frames(ctx context.Context, resources resource.Resou
valueField := fields.PropertyValueField(property, length)
qualityField := fields.QualityField(length)

frame := data.NewFrame(getFrameName(property), timeField, valueField, qualityField)
frame := data.NewFrame(getFrameName(property), timeField, valueField, qualityField)

if p.PropertyValue != nil {
if p.PropertyValue != nil && getPropertyVariantValue(p.PropertyValue.Value) != nil {
timeField.Set(0, getTime(p.PropertyValue.Timestamp))
valueField.Set(0, getPropertyVariantValue(p.PropertyValue.Value))
qualityField.Set(0, *p.PropertyValue.Quality)
}

return data.Frames{frame}, nil
}
}
2 changes: 1 addition & 1 deletion pkg/framer/property_value_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (AssetPropertyValueBatch) framePropertyValue(property *iotsitewise.Describe

frame := data.NewFrame(*property.AssetName, timeField, valueField, qualityField)

if assetPropertyValue != nil {
if assetPropertyValue != nil && getPropertyVariantValue(assetPropertyValue.Value) != nil {
timeField.Append(getTime(assetPropertyValue.Timestamp))
valueField.Append(getPropertyVariantValue(assetPropertyValue.Value))
qualityField.Append(*assetPropertyValue.Quality)
Expand Down
8 changes: 5 additions & 3 deletions pkg/framer/property_value_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func (p AssetPropertyValueHistory) Frames(ctx context.Context, resources resourc
}

for i, v := range p.AssetPropertyValueHistory {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
if v.Value != nil && getPropertyVariantValue(v.Value) != nil {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
}
}

return data.Frames{frame}, nil
Expand Down
9 changes: 5 additions & 4 deletions pkg/framer/property_value_history_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func (p AssetPropertyValueHistoryBatch) Frames(ctx context.Context, resources re

func (p AssetPropertyValueHistoryBatch) Frame(ctx context.Context, property *iotsitewise.DescribeAssetPropertyOutput, h []*iotsitewise.AssetPropertyValue) (*data.Frame, error) {
length := len(h)

// TODO: make this work with the API instead of ad-hoc dataType inference
// https://github.com/grafana/iot-sitewise-datasource/issues/98#issuecomment-892947756
if util.IsAssetProperty(property) && *property.AssetProperty.DataType == *aws.String("?") {
Expand Down Expand Up @@ -102,9 +101,11 @@ func (p AssetPropertyValueHistoryBatch) framePropertyValues(property *iotsitewis
}

for i, v := range h {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
if v.Value != nil && getPropertyVariantValue(v.Value) != nil {
timeField.Set(i, getTime(v.Timestamp))
valueField.Set(i, getPropertyVariantValue(v.Value))
qualityField.Set(i, *v.Quality)
}
}

return frame, nil
Expand Down

0 comments on commit 56d5f78

Please sign in to comment.