diff --git a/api/errors.go b/api/errors.go index 96eeffb7..c20ee464 100644 --- a/api/errors.go +++ b/api/errors.go @@ -9,6 +9,9 @@ var ErrMetadataNotAvailable = errors.New("meta data not available") // ErrDataNotAvailable indicates that no data set is yet available var ErrDataNotAvailable = errors.New("data not available") +// ErrDataInvalid indicates that the currently available data is not valid and should be ignored +var ErrDataInvalid = errors.New("data not valid") + // ErrDataForMetadataKeyNotFound indicates that no data item is found for the given key var ErrDataForMetadataKeyNotFound = errors.New("data for key not found") diff --git a/usecases/internal/measurement.go b/usecases/internal/measurement.go index 21b73484..09c72231 100644 --- a/usecases/internal/measurement.go +++ b/usecases/internal/measurement.go @@ -62,6 +62,12 @@ func MeasurementPhaseSpecificDataForFilter( } } + // if the value state is set and not normal, the value is not valid and should be ignored + // therefore we return an error + if item.ValueState != nil && *item.ValueState != model.MeasurementValueStateTypeNormal { + return nil, api.ErrDataInvalid + } + value := item.Value.GetValue() result = append(result, value) diff --git a/usecases/internal/measurement_test.go b/usecases/internal/measurement_test.go index d33190d2..05410387 100644 --- a/usecases/internal/measurement_test.go +++ b/usecases/internal/measurement_test.go @@ -161,4 +161,38 @@ func (s *InternalSuite) Test_MeasurementPhaseSpecificDataForFilter() { ) assert.Nil(s.T(), err) assert.Equal(s.T(), []float64{10, 10, 10}, data) + + measData = &model.MeasurementListDataType{ + MeasurementData: []model.MeasurementDataType{ + { + MeasurementId: util.Ptr(model.MeasurementIdType(10)), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + Value: model.NewScaledNumberType(10), + ValueState: util.Ptr(model.MeasurementValueStateTypeError), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + Value: model.NewScaledNumberType(10), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + Value: model.NewScaledNumberType(10), + }, + }, + } + + _, fErr = rFeature.UpdateData(true, model.FunctionTypeMeasurementListData, measData, nil, nil) + assert.Nil(s.T(), fErr) + + data, err = MeasurementPhaseSpecificDataForFilter( + s.localEntity, + s.monitoredEntity, + filter, + energyDirection, + ucapi.PhaseNameMapping, + ) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) }