From ea7bbb9ab2417c8293e5ccc6b8044c7f76c0d4b0 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 28 May 2024 19:41:25 +0200 Subject: [PATCH 1/3] Refactor features - Add local server features API at features/server - Move previous features API to features/client - Add interfaces and mocks for all features - Aligned up function names --- .mockery.yaml | 1 - api/errors.go | 2 + api/features.go | 244 ++++ api/featuresclient.go | 118 ++ api/featuresserver.go | 154 +++ features/api.go | 27 - features/{ => client}/deviceclassification.go | 21 +- features/client/deviceclassification_test.go | 58 + features/client/deviceconfiguration.go | 65 ++ features/client/deviceconfiguration_test.go | 101 ++ features/client/devicediagnosis.go | 46 + features/client/devicediagnosis_test.go | 65 ++ features/client/electricalconnection.go | 56 + features/client/electricalconnection_test.go | 79 ++ features/{ => client}/feature.go | 4 +- features/{ => client}/feature_test.go | 4 +- features/{ => client}/helper_test.go | 2 +- features/{ => client}/identification.go | 20 +- features/{ => client}/identification_test.go | 31 +- features/{ => client}/incentivetable.go | 74 +- features/{ => client}/incentivetable_test.go | 136 +-- features/client/loadcontrol.go | 70 ++ features/client/loadcontrol_test.go | 94 ++ features/client/measurement.go | 48 + features/client/measurement_test.go | 80 ++ .../{ => client}/smartenergymanagementps.go | 23 +- .../smartenergymanagementps_test.go | 37 +- features/client/timeseries.go | 67 ++ features/client/timeseries_test.go | 93 ++ features/deviceconfiguration.go | 157 --- features/deviceconfiguration_test.go | 281 ----- features/devicediagnosis.go | 74 -- features/devicediagnosis_test.go | 123 -- features/electricalconnection.go | 322 ----- features/electricalconnection_test.go | 582 ---------- features/internal/deviceclassification.go | 37 + .../deviceclassification_test.go | 41 +- features/internal/deviceconfiguration.go | 130 +++ features/internal/deviceconfiguration_test.go | 468 ++++++++ features/internal/devicediagnosis.go | 59 + features/internal/devicediagnosis_test.go | 122 ++ features/internal/electricalconnection.go | 276 +++++ .../internal/electricalconnection_test.go | 1031 +++++++++++++++++ features/internal/helper.go | 60 + features/internal/helper_test.go | 184 +++ features/internal/identification.go | 63 + features/internal/identification_test.go | 134 +++ features/internal/incentivetable.go | 71 ++ features/internal/incentivetable_test.go | 219 ++++ features/internal/loadcontrol.go | 131 +++ features/internal/loadcontrol_test.go | 355 ++++++ features/internal/measurement.go | 154 +++ features/internal/measurement_test.go | 371 ++++++ features/internal/smartenergymanagementps.go | 38 + .../internal/smartenergymanagementps_test.go | 87 ++ features/internal/timeseries.go | 80 ++ features/{ => internal}/timeseries_test.go | 180 +-- features/loadcontrol.go | 182 --- features/loadcontrol_test.go | 244 ---- features/measurement.go | 171 --- features/measurement_test.go | 237 ---- features/server/deviceconfiguration.go | 126 ++ features/server/deviceconfiguration_test.go | 245 ++++ features/server/devicediagnosis.go | 35 + features/server/devicediagnosis_test.go | 81 ++ features/server/electricalconnection.go | 185 +++ features/server/electricalconnection_test.go | 253 ++++ features/server/feature.go | 43 + features/server/feature_test.go | 82 ++ features/server/helper_test.go | 174 +++ features/server/loadcontrol.go | 124 ++ features/server/loadcontrol_test.go | 280 +++++ features/server/measurement.go | 126 ++ features/server/measurement_test.go | 203 ++++ features/timeseries.go | 150 --- go.mod | 2 +- go.sum | 4 +- .../emobility_measurement_test.go | 17 +- mocks/DeviceClassificationClientInterface.go | 92 ++ mocks/DeviceClassificationCommonInterface.go | 92 ++ mocks/DeviceClassificationServerInterface.go | 32 + mocks/DeviceConfigurationClientInterface.go | 486 ++++++++ mocks/DeviceConfigurationCommonInterface.go | 314 +++++ mocks/DeviceConfigurationServerInterface.go | 458 ++++++++ mocks/DeviceDiagnosisClientInterface.go | 149 +++ mocks/DeviceDiagnosisCommonInterface.go | 140 +++ mocks/DeviceDiagnosisServerInterface.go | 68 ++ mocks/ElectricalConnectionClientInterface.go | 263 +++++ mocks/ElectricalConnectionCommonInterface.go | 564 +++++++++ mocks/ElectricalConnectionServerInterface.go | 763 ++++++++++++ mocks/FeatureClientInterface.go | 322 +++++ mocks/FeatureServerInterface.go | 32 + mocks/IdentificationClientInterface.go | 92 ++ mocks/IdentificationCommonInterface.go | 139 +++ mocks/IdentificationServerInterface.go | 32 + mocks/IncentiveTableClientInterface.go | 322 +++++ mocks/IncentiveTableCommonInterface.go | 207 ++++ mocks/IncentiveTableServerInterface.go | 32 + mocks/LoadControlClientInterface.go | 264 +++++ mocks/LoadControlCommonInterface.go | 314 +++++ mocks/LoadControlServerInterface.go | 179 +++ mocks/MeasurementClientInterface.go | 206 ++++ mocks/MeasurementCommonInterface.go | 372 ++++++ mocks/MeasurementServerInterface.go | 179 +++ mocks/ServiceInterface.go | 45 + .../SmartEnergyManagementPsClientInterface.go | 150 +++ .../SmartEnergyManagementPsCommonInterface.go | 92 ++ .../SmartEnergyManagementPsServerInterface.go | 32 + mocks/TimeSeriesClientInterface.go | 264 +++++ mocks/TimeSeriesCommonInterface.go | 208 ++++ mocks/TimeSeriesServerInterface.go | 32 + 111 files changed, 14597 insertions(+), 2953 deletions(-) create mode 100644 api/features.go create mode 100644 api/featuresclient.go create mode 100644 api/featuresserver.go delete mode 100644 features/api.go rename features/{ => client}/deviceclassification.go (65%) create mode 100644 features/client/deviceclassification_test.go create mode 100644 features/client/deviceconfiguration.go create mode 100644 features/client/deviceconfiguration_test.go create mode 100644 features/client/devicediagnosis.go create mode 100644 features/client/devicediagnosis_test.go create mode 100644 features/client/electricalconnection.go create mode 100644 features/client/electricalconnection_test.go rename features/{ => client}/feature.go (98%) rename features/{ => client}/feature_test.go (97%) rename features/{ => client}/helper_test.go (99%) rename features/{ => client}/identification.go (64%) rename features/{ => client}/identification_test.go (60%) rename features/{ => client}/incentivetable.go (56%) rename features/{ => client}/incentivetable_test.go (52%) create mode 100644 features/client/loadcontrol.go create mode 100644 features/client/loadcontrol_test.go create mode 100644 features/client/measurement.go create mode 100644 features/client/measurement_test.go rename features/{ => client}/smartenergymanagementps.go (66%) rename features/{ => client}/smartenergymanagementps_test.go (60%) create mode 100644 features/client/timeseries.go create mode 100644 features/client/timeseries_test.go delete mode 100644 features/deviceconfiguration.go delete mode 100644 features/deviceconfiguration_test.go delete mode 100644 features/devicediagnosis.go delete mode 100644 features/devicediagnosis_test.go delete mode 100644 features/electricalconnection.go delete mode 100644 features/electricalconnection_test.go create mode 100644 features/internal/deviceclassification.go rename features/{ => internal}/deviceclassification_test.go (67%) create mode 100644 features/internal/deviceconfiguration.go create mode 100644 features/internal/deviceconfiguration_test.go create mode 100644 features/internal/devicediagnosis.go create mode 100644 features/internal/devicediagnosis_test.go create mode 100644 features/internal/electricalconnection.go create mode 100644 features/internal/electricalconnection_test.go create mode 100644 features/internal/helper.go create mode 100644 features/internal/helper_test.go create mode 100644 features/internal/identification.go create mode 100644 features/internal/identification_test.go create mode 100644 features/internal/incentivetable.go create mode 100644 features/internal/incentivetable_test.go create mode 100644 features/internal/loadcontrol.go create mode 100644 features/internal/loadcontrol_test.go create mode 100644 features/internal/measurement.go create mode 100644 features/internal/measurement_test.go create mode 100644 features/internal/smartenergymanagementps.go create mode 100644 features/internal/smartenergymanagementps_test.go create mode 100644 features/internal/timeseries.go rename features/{ => internal}/timeseries_test.go (51%) delete mode 100644 features/loadcontrol.go delete mode 100644 features/loadcontrol_test.go delete mode 100644 features/measurement.go delete mode 100644 features/measurement_test.go create mode 100644 features/server/deviceconfiguration.go create mode 100644 features/server/deviceconfiguration_test.go create mode 100644 features/server/devicediagnosis.go create mode 100644 features/server/devicediagnosis_test.go create mode 100644 features/server/electricalconnection.go create mode 100644 features/server/electricalconnection_test.go create mode 100644 features/server/feature.go create mode 100644 features/server/feature_test.go create mode 100644 features/server/helper_test.go create mode 100644 features/server/loadcontrol.go create mode 100644 features/server/loadcontrol_test.go create mode 100644 features/server/measurement.go create mode 100644 features/server/measurement_test.go delete mode 100644 features/timeseries.go create mode 100644 mocks/DeviceClassificationClientInterface.go create mode 100644 mocks/DeviceClassificationCommonInterface.go create mode 100644 mocks/DeviceClassificationServerInterface.go create mode 100644 mocks/DeviceConfigurationClientInterface.go create mode 100644 mocks/DeviceConfigurationCommonInterface.go create mode 100644 mocks/DeviceConfigurationServerInterface.go create mode 100644 mocks/DeviceDiagnosisClientInterface.go create mode 100644 mocks/DeviceDiagnosisCommonInterface.go create mode 100644 mocks/DeviceDiagnosisServerInterface.go create mode 100644 mocks/ElectricalConnectionClientInterface.go create mode 100644 mocks/ElectricalConnectionCommonInterface.go create mode 100644 mocks/ElectricalConnectionServerInterface.go create mode 100644 mocks/FeatureClientInterface.go create mode 100644 mocks/FeatureServerInterface.go create mode 100644 mocks/IdentificationClientInterface.go create mode 100644 mocks/IdentificationCommonInterface.go create mode 100644 mocks/IdentificationServerInterface.go create mode 100644 mocks/IncentiveTableClientInterface.go create mode 100644 mocks/IncentiveTableCommonInterface.go create mode 100644 mocks/IncentiveTableServerInterface.go create mode 100644 mocks/LoadControlClientInterface.go create mode 100644 mocks/LoadControlCommonInterface.go create mode 100644 mocks/LoadControlServerInterface.go create mode 100644 mocks/MeasurementClientInterface.go create mode 100644 mocks/MeasurementCommonInterface.go create mode 100644 mocks/MeasurementServerInterface.go create mode 100644 mocks/SmartEnergyManagementPsClientInterface.go create mode 100644 mocks/SmartEnergyManagementPsCommonInterface.go create mode 100644 mocks/SmartEnergyManagementPsServerInterface.go create mode 100644 mocks/TimeSeriesClientInterface.go create mode 100644 mocks/TimeSeriesCommonInterface.go create mode 100644 mocks/TimeSeriesServerInterface.go diff --git a/.mockery.yaml b/.mockery.yaml index d4b533e7..d9ddb1bb 100644 --- a/.mockery.yaml +++ b/.mockery.yaml @@ -7,4 +7,3 @@ filename: "{{.InterfaceName}}.go" all: True packages: github.com/enbility/eebus-go/api: - github.com/enbility/eebus-go/features: diff --git a/api/errors.go b/api/errors.go index 59200057..5ef6d889 100644 --- a/api/errors.go +++ b/api/errors.go @@ -23,3 +23,5 @@ var ErrFunctionNotSupported = errors.New("function is not supported") var ErrOperationOnFunctionNotSupported = errors.New("operation is not supported on function") var ErrMissingData = errors.New("missing data") + +var ErrDeviceDisconnected = errors.New("device is disconnected") diff --git a/api/features.go b/api/features.go new file mode 100644 index 00000000..61d735de --- /dev/null +++ b/api/features.go @@ -0,0 +1,244 @@ +package api + +import ( + "time" + + "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +// Feature client interface were the local feature role is client and the remote feature role is server +type FeatureClientInterface interface { + // check if there is a subscription to the remote feature + HasSubscription() bool + + // subscribe to the feature of the entity + Subscribe() (*model.MsgCounterType, error) + + // check if there is a binding to the remote feature + HasBinding() bool + + // bind to the feature of the entity + Bind() (*model.MsgCounterType, error) + + // add a callback function to be invoked once a result or reply message for a msgCounter came in + AddResponseCallback(msgCounterReference model.MsgCounterType, function func(msg api.ResponseMessage)) error + + // add a callback function to be invoked once a result came in + AddResultCallback(function func(msg api.ResponseMessage)) +} + +// Feature server interface were the local feature role is a server +type FeatureServerInterface interface { +} + +// Common interface for DeviceClassificationClientInterface and DeviceClassificationServerInterface +type DeviceClassificationCommonInterface interface { + // get the current manufacturer details for a remote device entity + GetManufacturerDetails() (*model.DeviceClassificationManufacturerDataType, error) +} + +// Common interface for DeviceConfigurationClientInterface and DeviceConfigurationServerInterface +type DeviceConfigurationCommonInterface interface { + // check if spine.EventPayload Data contains data for a given filter + // + // data type will be checked for model.DeviceConfigurationKeyValueListDataType, + // filter type will be checked for model.DeviceConfigurationKeyValueDescriptionDataType + CheckEventPayloadDataForFilter(payloadData any, filter any) bool + + // Get the description for a given keyId + // + // Will return nil if no matching description was found + GetKeyValueDescriptionFoKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) + + // Get the description for a given value combination + // + // Returns an error if no matching description was found + GetKeyValueDescriptionsForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) + + // Get the key value data for a given keyId + // + // Will return nil if no matching data was found + GetKeyValueDataForKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error) + + // Get key value data for a given filter + // + // Will return nil if no matching data was found + GetKeyValueDataForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error) +} + +// Common interface for DeviceDiagnosisClientInterface and DeviceDiagnosisServerInterface +type DeviceDiagnosisCommonInterface interface { + // get the current diagnosis state for an device entity + GetState() (*model.DeviceDiagnosisStateDataType, error) + + // check if the currently available heartbeat data is within a time duration + IsHeartbeatWithinDuration(duration time.Duration) bool +} + +// Common interface for ElectricalConnectionClientInterface and ElectricalConnectionServerInterface +type ElectricalConnectionCommonInterface interface { + // check if spine.EventPayload Data contains data for a given filter + // + // data type will be checked for model.ElectricalConnectionPermittedValueSetListDataType, + // filter type will be checked for model.ElectricalConnectionParameterDescriptionDataType + CheckEventPayloadDataForFilter(payloadData any, filter any) bool + + // Get the description for a given filter + // + // Returns an error if no matching description is found + GetDescriptionsForFilter( + filter model.ElectricalConnectionDescriptionDataType, + ) ([]model.ElectricalConnectionDescriptionDataType, error) + + // Get the description for a given parameter description + // + // Returns an error if no matching description is found + GetDescriptionForParameterDescriptionFilter( + filter model.ElectricalConnectionParameterDescriptionDataType) ( + *model.ElectricalConnectionDescriptionDataType, error) + + // Get the description for a given filter + // + // Returns an error if no matching description is found + GetParameterDescriptionsForFilter( + filter model.ElectricalConnectionParameterDescriptionDataType, + ) ([]model.ElectricalConnectionParameterDescriptionDataType, error) + + // return permitted values for all Electrical Connections + GetPermittedValueSetForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) ( + []model.ElectricalConnectionPermittedValueSetDataType, error) + + // returns minimum, maximum, default/pause limit values + GetPermittedValueDataForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) ( + float64, float64, float64, error) + + // Get the min, max, default current limits for each phase + GetPhaseCurrentLimits() ( + resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error) + + // Adjust a value to be within the permitted value range + AdjustValueToBeWithinPermittedValuesForParameterId( + value float64, parameterId model.ElectricalConnectionParameterIdType) float64 + + // Get the characteristics for a given filter + // + // Returns an error if no matching description is found + GetCharacteristicsForFilter( + filter model.ElectricalConnectionCharacteristicDataType, + ) ([]model.ElectricalConnectionCharacteristicDataType, error) +} + +// Common interface for LoadControlClientInterface and LoadControlServerInterface +type LoadControlCommonInterface interface { + // check if spine.EventPayload Data contains data for a given filter + // + // data type will be checked for model.LoadControlLimitListDataType, + // filter type will be checked for model.LoadControlLimitDescriptionDataType + CheckEventPayloadDataForFilter(payloadData any, filter any) bool + + // Get the description for a given limitId + // + // Will return nil if no matching description is found + GetLimitDescriptionForId(limitId model.LoadControlLimitIdType) ( + *model.LoadControlLimitDescriptionDataType, error) + + // Get the description for a given filter + // + // Returns an error if no matching description is found + GetLimitDescriptionsForFilter( + filter model.LoadControlLimitDescriptionDataType, + ) ([]model.LoadControlLimitDescriptionDataType, error) + + // Get the description for a given limitId + // + // Will return nil if no data is available + GetLimitDataForId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error) + + // Get limit data for a given filter + // + // Will return nil if no data is available + GetLimitDataForFilter(filter model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDataType, error) +} + +// Common interface for MeasurementClientInterface and MeasurementServerInterface +type MeasurementCommonInterface interface { + // check if spine.EventPayload Data contains data for a given filter + // + // data type will be checked for model.MeasurementListDataType, + // filter type will be checked for model.MeasurementDescriptionDataType + CheckEventPayloadDataForFilter(payloadData any, filter any) bool + + // Get the description for a given id + // + // Returns an error if no matching description is found + GetDescriptionForId( + measurementId model.MeasurementIdType, + ) (*model.MeasurementDescriptionDataType, error) + + // Get the description for a given filter + // + // Returns an error if no matching description is found + GetDescriptionsForFilter( + filter model.MeasurementDescriptionDataType, + ) ([]model.MeasurementDescriptionDataType, error) + + // Get the constraints for a given filter + // + // Returns an error if no matching constraint is found + GetConstraintsForFilter( + filter model.MeasurementConstraintsDataType, + ) ([]model.MeasurementConstraintsDataType, error) + + // Get the measuement data for a given measurementId + // + // Will return nil if no data is available + GetDataForId(measurementId model.MeasurementIdType) (*model.MeasurementDataType, error) + + // Get measuement data for a given filter + // + // Will return nil if no data is available + GetDataForFilter(filter model.MeasurementDescriptionDataType) ( + []model.MeasurementDataType, error) +} + +// Common interface for IdentificationClientInterface and IdentificationServerInterface +type IdentificationCommonInterface interface { + // check if spine.EventPayload Data contains identification data + // + // data type will be checked for model.IdentificationListDataType + CheckEventPayloadDataForFilter(payloadData any) bool + + // return current values for Identification + GetDataForFilter(filter model.IdentificationDataType) ([]model.IdentificationDataType, error) +} + +// Common interface for IncentiveTableClientInterface and IncentiveTableServerInterface +type IncentiveTableCommonInterface interface { + // return list of descriptions for a given filter + GetDescriptionsForFilter(filter model.TariffDescriptionDataType) ([]model.IncentiveTableDescriptionType, error) + + // return list of constraints + GetConstraints() ([]model.IncentiveTableConstraintsType, error) + + // return current data for Time Series + GetData() ([]model.IncentiveTableType, error) +} + +// Common interface for SmartEnergyManagementPsClientInterface and SmartEnergyManagementPsServerInterface +type SmartEnergyManagementPsCommonInterface interface { + // return current data for FunctionTypeSmartEnergyManagementPsData + GetData() (*model.SmartEnergyManagementPsDataType, error) +} + +// Common interface for TimeSeriesClientInterface and TimeSeriesServerInterface +type TimeSeriesCommonInterface interface { + // return list of descriptions for a given filter + GetDescriptionsForFilter(filter model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDescriptionDataType, error) + + // return current constraints for Time Series + GetConstraints() ([]model.TimeSeriesConstraintsDataType, error) + + // return current data for Time Series for a given filter + GetDataForFilter(filter model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDataType, error) +} diff --git a/api/featuresclient.go b/api/featuresclient.go new file mode 100644 index 00000000..dcb5302d --- /dev/null +++ b/api/featuresclient.go @@ -0,0 +1,118 @@ +package api + +import "github.com/enbility/spine-go/model" + +type DeviceClassificationClientInterface interface { + // request DeviceClassificationManufacturerData from a remote device entity + RequestManufacturerDetails() (*model.MsgCounterType, error) +} + +type DeviceConfigurationClientInterface interface { + DeviceConfigurationCommonInterface + + // request DeviceConfigurationDescriptionListData from a remote entity + RequestDescriptions() (*model.MsgCounterType, error) + + // request DeviceConfigurationKeyValueListData from a remote entity + RequestKeyValues() (*model.MsgCounterType, error) + + // write key values + // returns an error if this failed + WriteKeyValues(data []model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error) +} + +type DeviceDiagnosisClientInterface interface { + // request DeviceDiagnosisStateData from a remote entity + RequestState() (*model.MsgCounterType, error) + + // request FunctionTypeDeviceDiagnosisHeartbeatData from a remote device + RequestHeartbeat() (*model.MsgCounterType, error) +} + +type ElectricalConnectionClientInterface interface { + // request ElectricalConnectionDescriptionListDataType from a remote entity + RequestDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeElectricalConnectionParameterDescriptionListData from a remote entity + RequestParameterDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeElectricalConnectionPermittedValueSetListData from a remote entity + RequestPermittedValueSets() (*model.MsgCounterType, error) + + // request FunctionTypeElectricalConnectionCharacteristicListData from a remote entity + RequestCharacteristics() (*model.MsgCounterType, error) +} + +type IdentificationClientInterface interface { + // request FunctionTypeIdentificationListData from a remote entity + RequestValues() (*model.MsgCounterType, error) +} + +type IncentiveTableClientInterface interface { + // request FunctionTypeIncentiveTableDescriptionData from a remote entity + RequestDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeIncentiveTableConstraintsData from a remote entity + RequestConstraints() (*model.MsgCounterType, error) + + // request FunctionTypeIncentiveTableData from a remote entity + RequestValues() (*model.MsgCounterType, error) + + // write incentivetable descriptions + // returns an error if this failed + WriteDescriptions(data []model.IncentiveTableDescriptionType) (*model.MsgCounterType, error) + + // write incentivetable descriptions + // returns an error if this failed + WriteValues(data []model.IncentiveTableType) (*model.MsgCounterType, error) +} + +type LoadControlClientInterface interface { + // request FunctionTypeLoadControlLimitDescriptionListData from a remote device + RequestLimitDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeLoadControlLimitConstraintsListData from a remote device + RequestLimitConstraints() (*model.MsgCounterType, error) + + // request FunctionTypeLoadControlLimitListData from a remote device + RequestLimitData() (*model.MsgCounterType, error) + + // write load control limits + // returns an error if this failed + WriteLimitData(data []model.LoadControlLimitDataType) (*model.MsgCounterType, error) +} + +type MeasurementClientInterface interface { + // request FunctionTypeMeasurementDescriptionListData from a remote device + RequestDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeMeasurementConstraintsListData from a remote entity + RequestConstraints() (*model.MsgCounterType, error) + + // request FunctionTypeMeasurementListData from a remote entity + RequestData() (*model.MsgCounterType, error) +} + +type SmartEnergyManagementPsClientInterface interface { + // request FunctionTypeSmartEnergyManagementPsData from a remote entity + RequestData() (*model.MsgCounterType, error) + + // write SmartEnergyManagementPsData + // returns an error if this failed + WriteData(data *model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error) +} + +type TimeSeriesClientInterface interface { + // request FunctionTypeTimeSeriesDescriptionListData from a remote entity + RequestDescriptions() (*model.MsgCounterType, error) + + // request FunctionTypeTimeSeriesConstraintsListData from a remote entity + RequestConstraints() (*model.MsgCounterType, error) + + // request FunctionTypeTimeSeriesListData from a remote device + RequestData() (*model.MsgCounterType, error) + + // write Time Series values + // returns an error if this failed + WriteData(data []model.TimeSeriesDataType) (*model.MsgCounterType, error) +} diff --git a/api/featuresserver.go b/api/featuresserver.go new file mode 100644 index 00000000..be02d89e --- /dev/null +++ b/api/featuresserver.go @@ -0,0 +1,154 @@ +package api + +import "github.com/enbility/spine-go/model" + +type DeviceClassificationServerInterface interface { +} + +type DeviceConfigurationServerInterface interface { + DeviceConfigurationCommonInterface + + // Add a new description data set and return the keyId + // + // will return nil if the data set could not be added + AddKeyValueDescription(description model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyIdType + + // Set or update data set for a keyId + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateKeyValueDataForKeyId( + data model.DeviceConfigurationKeyValueDataType, + deleteElements *model.DeviceConfigurationKeyValueDataElementsType, + keyId model.DeviceConfigurationKeyIdType, + ) error + + // Set or update data set for a filter + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateKeyValueDataForFilter( + data model.DeviceConfigurationKeyValueDataType, + deleteElements *model.DeviceConfigurationKeyValueDataElementsType, + filter model.DeviceConfigurationKeyValueDescriptionDataType, + ) error +} + +type DeviceDiagnosisServerInterface interface { + // set the local diagnosis state of the device + SetLocalState(operatingState *model.DeviceDiagnosisStateDataType) +} + +type ElectricalConnectionServerInterface interface { + ElectricalConnectionCommonInterface + + // Add a new description data set + // + // NOTE: the electricalConnectionId has to be provided + // + // will return nil if the data set could not be added + AddDescription( + description model.ElectricalConnectionDescriptionDataType, + ) error + + // Add a new parameter description data sett and return the parameterId + // + // NOTE: the electricalConnectionId has to be provided, parameterId may not be provided + // + // will return nil if the data set could not be added + AddParameterDescription( + description model.ElectricalConnectionParameterDescriptionDataType, + ) *model.ElectricalConnectionParameterIdType + + // Add a new characteristic data set + // + // Note: ElectricalConnectionId and ParameterId must be set, CharacteristicId will be set automatically + // + // Will return an error if the data set could not be added + AddCharacteristic(data model.ElectricalConnectionCharacteristicDataType) (*model.ElectricalConnectionCharacteristicIdType, error) + + // Update data set for a filter + // Elements provided in deleteElements will be removed from the data set before the update + // + // // ElectricalConnectionId, ParameterId and CharacteristicId must be set + // + // Will return an error if the data set could not be updated + UpdateCharacteristic( + data model.ElectricalConnectionCharacteristicDataType, + deleteElements *model.ElectricalConnectionCharacteristicDataElementsType, + ) error +} + +type LoadControlServerInterface interface { + // Add a new description data set and return the limitId + // + // NOTE: the limitId may not be provided + // + // will return nil if the data set could not be added + AddLimitDescription( + description model.LoadControlLimitDescriptionDataType, + ) *model.LoadControlLimitIdType + + // Set or update data set for a limitId + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateLimitDataForId( + data model.LoadControlLimitDataType, + deleteElements *model.LoadControlLimitDataElementsType, + limitId model.LoadControlLimitIdType, + ) error + + // Set or update data set for a filter + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateLimitDataForFilter( + data model.LoadControlLimitDataType, + deleteElements *model.LoadControlLimitDataElementsType, + filter model.LoadControlLimitDescriptionDataType, + ) error +} + +type MeasurementServerInterface interface { + // Add a new parameter description data sett and return the measurementId + // + // NOTE: the measurementId may not be provided + // + // will return nil if the data set could not be added + AddDescription( + description model.MeasurementDescriptionDataType, + ) *model.MeasurementIdType + + // Set or update data set for a measurementId + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateDataForId( + data model.MeasurementDataType, + deleteElements *model.MeasurementDataElementsType, + measurementId model.MeasurementIdType, + ) error + + // Set or update data set for a filter + // Elements provided in deleteElements will be removed from the data set before the update + // + // Will return an error if the data set could not be updated + UpdateDataForFilter( + data model.MeasurementDataType, + deleteElements *model.MeasurementDataElementsType, + filter model.MeasurementDescriptionDataType, + ) error +} + +type IdentificationServerInterface interface { +} + +type IncentiveTableServerInterface interface { +} + +type SmartEnergyManagementPsServerInterface interface { +} + +type TimeSeriesServerInterface interface { +} diff --git a/features/api.go b/features/api.go deleted file mode 100644 index edb4db43..00000000 --- a/features/api.go +++ /dev/null @@ -1,27 +0,0 @@ -package features - -import ( - "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" -) - -// Feature interface were the local feature role is client and the remote feature role is server -type FeatureInterface interface { - // check if there is a subscription to the remote feature - HasSubscription() bool - - // subscribe to the feature of the entity - Subscribe() (*model.MsgCounterType, error) - - // check if there is a binding to the remote feature - HasBinding() bool - - // bind to the feature of the entity - Bind() (*model.MsgCounterType, error) - - // add a callback function to be invoked once a result or reply message for a msgCounter came in - AddResponseCallback(msgCounterReference model.MsgCounterType, function func(msg api.ResponseMessage)) error - - // add a callback function to be invoked once a result came in - AddResultCallback(function func(msg api.ResponseMessage)) -} diff --git a/features/deviceclassification.go b/features/client/deviceclassification.go similarity index 65% rename from features/deviceclassification.go rename to features/client/deviceclassification.go index b5fbeb76..9a4f0a4f 100644 --- a/features/deviceclassification.go +++ b/features/client/deviceclassification.go @@ -1,14 +1,16 @@ -package features +package client import ( "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" ) type DeviceClassification struct { *Feature + + *internal.DeviceClassificationCommon } // Get a new DeviceClassification features helper @@ -24,23 +26,16 @@ func NewDeviceClassification( } dc := &DeviceClassification{ - Feature: feature, + Feature: feature, + DeviceClassificationCommon: internal.NewRemoteDeviceClassification(feature.featureRemote), } return dc, nil } +var _ api.DeviceClassificationClientInterface = (*DeviceClassification)(nil) + // request DeviceClassificationManufacturerData from a remote device entity func (d *DeviceClassification) RequestManufacturerDetails() (*model.MsgCounterType, error) { return d.requestData(model.FunctionTypeDeviceClassificationManufacturerData, nil, nil) } - -// get the current manufacturer details for a remote device entity -func (d *DeviceClassification) GetManufacturerDetails() (*model.DeviceClassificationManufacturerDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.DeviceClassificationManufacturerDataType](d.featureRemote, model.FunctionTypeDeviceClassificationManufacturerData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data, nil -} diff --git a/features/client/deviceclassification_test.go b/features/client/deviceclassification_test.go new file mode 100644 index 00000000..24318df0 --- /dev/null +++ b/features/client/deviceclassification_test.go @@ -0,0 +1,58 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestDeviceClassificationSuite(t *testing.T) { + suite.Run(t, new(DeviceClassificationSuite)) +} + +type DeviceClassificationSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + deviceClassification *features.DeviceClassification + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*DeviceClassificationSuite)(nil) + +func (s *DeviceClassificationSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *DeviceClassificationSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeDeviceClassification, + functions: []model.FunctionType{ + model.FunctionTypeDeviceClassificationManufacturerData, + }, + }, + }, + ) + + var err error + s.deviceClassification, err = features.NewDeviceClassification(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.deviceClassification) +} + +func (s *DeviceClassificationSuite) Test_RequestManufacturerDetails() { + counter, err := s.deviceClassification.RequestManufacturerDetails() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/client/deviceconfiguration.go b/features/client/deviceconfiguration.go new file mode 100644 index 00000000..ca6fb2db --- /dev/null +++ b/features/client/deviceconfiguration.go @@ -0,0 +1,65 @@ +package client + +import ( + "github.com/enbility/eebus-go/api" + internal "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceConfiguration struct { + *Feature + + *internal.DeviceConfigurationCommon +} + +// Get a new DeviceConfiguration features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewDeviceConfiguration( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*DeviceConfiguration, error) { + feature, err := NewFeature(model.FeatureTypeTypeDeviceConfiguration, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + dc := &DeviceConfiguration{ + Feature: feature, + DeviceConfigurationCommon: internal.NewRemoteDeviceConfiguration(feature.featureRemote), + } + + return dc, nil +} + +var _ api.DeviceConfigurationClientInterface = (*DeviceConfiguration)(nil) + +// request DeviceConfiguration data from a remote entity +func (d *DeviceConfiguration) RequestDescriptions() (*model.MsgCounterType, error) { + return d.requestData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, nil, nil) +} + +// request DeviceConfigurationKeyValueListDataType from a remote entity +func (d *DeviceConfiguration) RequestKeyValues() (*model.MsgCounterType, error) { + return d.requestData(model.FunctionTypeDeviceConfigurationKeyValueListData, nil, nil) +} + +// write key values +// returns an error if this failed +func (d *DeviceConfiguration) WriteKeyValues(data []model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error) { + if len(data) == 0 { + return nil, api.ErrMissingData + } + + cmd := model.CmdType{ + Function: util.Ptr(model.FunctionTypeDeviceConfigurationKeyValueListData), + Filter: []model.FilterType{*model.NewFilterTypePartial()}, + DeviceConfigurationKeyValueListData: &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: data, + }, + } + + return d.remoteDevice.Sender().Write(d.featureLocal.Address(), d.featureRemote.Address(), cmd) +} diff --git a/features/client/deviceconfiguration_test.go b/features/client/deviceconfiguration_test.go new file mode 100644 index 00000000..5f74d8d3 --- /dev/null +++ b/features/client/deviceconfiguration_test.go @@ -0,0 +1,101 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestDeviceConfigurationSuite(t *testing.T) { + suite.Run(t, new(DeviceConfigurationSuite)) +} + +type DeviceConfigurationSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface + + deviceConfiguration *features.DeviceConfiguration +} + +const remoteSki string = "testremoteski" + +func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeDeviceConfiguration, + functions: []model.FunctionType{ + model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, + model.FunctionTypeDeviceConfigurationKeyValueListData, + }, + }, + }, + ) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var err error + s.deviceConfiguration, err = features.NewDeviceConfiguration(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.deviceConfiguration) +} + +func (s *DeviceConfigurationSuite) Test_RequestDescriptions() { + counter, err := s.deviceConfiguration.RequestDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *DeviceConfigurationSuite) Test_RequestKeyValueList() { + counter, err := s.deviceConfiguration.RequestKeyValues() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *DeviceConfigurationSuite) Test_WriteValues() { + counter, err := s.deviceConfiguration.WriteKeyValues(nil) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data := []model.DeviceConfigurationKeyValueDataType{} + counter, err = s.deviceConfiguration.WriteKeyValues(data) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data = []model.DeviceConfigurationKeyValueDataType{ + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + Value: &model.DeviceConfigurationKeyValueValueType{ + ScaledNumber: model.NewScaledNumberType(10), + }, + }, + } + counter, err = s.deviceConfiguration.WriteKeyValues(data) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/client/devicediagnosis.go b/features/client/devicediagnosis.go new file mode 100644 index 00000000..f1b5008d --- /dev/null +++ b/features/client/devicediagnosis.go @@ -0,0 +1,46 @@ +package client + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceDiagnosis struct { + *Feature + + *internal.DeviceDiagnosisCommon +} + +// Get a new DeviceDiagnosis features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewDeviceDiagnosis( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*DeviceDiagnosis, error) { + feature, err := NewFeature(model.FeatureTypeTypeDeviceDiagnosis, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + dd := &DeviceDiagnosis{ + Feature: feature, + DeviceDiagnosisCommon: internal.NewRemoteDeviceDiagnosis(feature.featureRemote), + } + + return dd, nil +} + +var _ api.DeviceDiagnosisClientInterface = (*DeviceDiagnosis)(nil) + +// request DeviceDiagnosisStateData from a remote entity +func (d *DeviceDiagnosis) RequestState() (*model.MsgCounterType, error) { + return d.requestData(model.FunctionTypeDeviceDiagnosisStateData, nil, nil) +} + +// request FunctionTypeDeviceDiagnosisHeartbeatData from a remote device +func (d *DeviceDiagnosis) RequestHeartbeat() (*model.MsgCounterType, error) { + return d.requestData(model.FunctionTypeDeviceDiagnosisHeartbeatData, nil, nil) +} diff --git a/features/client/devicediagnosis_test.go b/features/client/devicediagnosis_test.go new file mode 100644 index 00000000..911fb436 --- /dev/null +++ b/features/client/devicediagnosis_test.go @@ -0,0 +1,65 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestDeviceDiagnosisSuite(t *testing.T) { + suite.Run(t, new(DeviceDiagnosisSuite)) +} + +type DeviceDiagnosisSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + deviceDiagnosis *features.DeviceDiagnosis + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*DeviceDiagnosisSuite)(nil) + +func (s *DeviceDiagnosisSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeDeviceDiagnosis, + functions: []model.FunctionType{ + model.FunctionTypeDeviceDiagnosisStateData, + model.FunctionTypeDeviceDiagnosisHeartbeatData, + }, + }, + }, + ) + + var err error + s.deviceDiagnosis, err = features.NewDeviceDiagnosis(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.deviceDiagnosis) +} + +func (s *DeviceDiagnosisSuite) Test_RequestHeartbeat() { + counter, err := s.deviceDiagnosis.RequestHeartbeat() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *DeviceDiagnosisSuite) Test_RequestState() { + counter, err := s.deviceDiagnosis.RequestState() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/client/electricalconnection.go b/features/client/electricalconnection.go new file mode 100644 index 00000000..6881b084 --- /dev/null +++ b/features/client/electricalconnection.go @@ -0,0 +1,56 @@ +package client + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type ElectricalConnection struct { + *Feature + + *internal.ElectricalConnectionCommon +} + +// Get a new ElectricalConnection features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewElectricalConnection( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*ElectricalConnection, error) { + feature, err := NewFeature(model.FeatureTypeTypeElectricalConnection, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + e := &ElectricalConnection{ + Feature: feature, + ElectricalConnectionCommon: internal.NewRemoteElectricalConnection(feature.featureRemote), + } + + return e, nil +} + +var _ api.ElectricalConnectionClientInterface = (*ElectricalConnection)(nil) + +// request ElectricalConnectionDescriptionListDataType from a remote entity +func (e *ElectricalConnection) RequestDescriptions() (*model.MsgCounterType, error) { + return e.requestData(model.FunctionTypeElectricalConnectionDescriptionListData, nil, nil) +} + +// request FunctionTypeElectricalConnectionParameterDescriptionListData from a remote entity +func (e *ElectricalConnection) RequestParameterDescriptions() (*model.MsgCounterType, error) { + return e.requestData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, nil, nil) +} + +// request FunctionTypeElectricalConnectionPermittedValueSetListData from a remote entity +func (e *ElectricalConnection) RequestPermittedValueSets() (*model.MsgCounterType, error) { + return e.requestData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, nil, nil) +} + +// request FunctionTypeElectricalConnectionCharacteristicListData from a remote entity +func (e *ElectricalConnection) RequestCharacteristics() (*model.MsgCounterType, error) { + return e.requestData(model.FunctionTypeElectricalConnectionCharacteristicListData, nil, nil) +} diff --git a/features/client/electricalconnection_test.go b/features/client/electricalconnection_test.go new file mode 100644 index 00000000..6cb54d2c --- /dev/null +++ b/features/client/electricalconnection_test.go @@ -0,0 +1,79 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestElectricalConnectionSuite(t *testing.T) { + suite.Run(t, new(ElectricalConnectionSuite)) +} + +type ElectricalConnectionSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + electricalConnection *features.ElectricalConnection + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*ElectricalConnectionSuite)(nil) + +func (s *ElectricalConnectionSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeElectricalConnection, + functions: []model.FunctionType{ + model.FunctionTypeElectricalConnectionDescriptionListData, + model.FunctionTypeElectricalConnectionParameterDescriptionListData, + model.FunctionTypeElectricalConnectionPermittedValueSetListData, + model.FunctionTypeElectricalConnectionCharacteristicListData, + }, + }, + }, + ) + + var err error + s.electricalConnection, err = features.NewElectricalConnection(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.electricalConnection) +} + +func (s *ElectricalConnectionSuite) Test_RequestDescriptions() { + counter, err := s.electricalConnection.RequestDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *ElectricalConnectionSuite) Test_RequestParameterDescriptions() { + counter, err := s.electricalConnection.RequestParameterDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *ElectricalConnectionSuite) Test_RequestPermittedValueSets() { + counter, err := s.electricalConnection.RequestPermittedValueSets() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *ElectricalConnectionSuite) Test_RequestCharacteristics() { + counter, err := s.electricalConnection.RequestCharacteristics() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/feature.go b/features/client/feature.go similarity index 98% rename from features/feature.go rename to features/client/feature.go index 2af86fb1..f3c50bf2 100644 --- a/features/feature.go +++ b/features/client/feature.go @@ -1,4 +1,4 @@ -package features +package client import ( "errors" @@ -24,7 +24,7 @@ type Feature struct { remoteEntity spineapi.EntityRemoteInterface } -var _ FeatureInterface = (*Feature)(nil) +var _ api.FeatureClientInterface = (*Feature)(nil) func NewFeature( featureType model.FeatureTypeType, diff --git a/features/feature_test.go b/features/client/feature_test.go similarity index 97% rename from features/feature_test.go rename to features/client/feature_test.go index b6e57899..ac851fd9 100644 --- a/features/feature_test.go +++ b/features/client/feature_test.go @@ -1,9 +1,9 @@ -package features_test +package client_test import ( "testing" - "github.com/enbility/eebus-go/features" + features "github.com/enbility/eebus-go/features/client" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" diff --git a/features/helper_test.go b/features/client/helper_test.go similarity index 99% rename from features/helper_test.go rename to features/client/helper_test.go index 357403e0..0e2ebc04 100644 --- a/features/helper_test.go +++ b/features/client/helper_test.go @@ -1,4 +1,4 @@ -package features_test +package client_test import ( "encoding/json" diff --git a/features/identification.go b/features/client/identification.go similarity index 64% rename from features/identification.go rename to features/client/identification.go index 4d69c325..ea93486d 100644 --- a/features/identification.go +++ b/features/client/identification.go @@ -1,14 +1,15 @@ -package features +package client import ( - "github.com/enbility/eebus-go/api" + internal "github.com/enbility/eebus-go/features/internal" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" ) type Identification struct { *Feature + + *internal.IdentificationCommon } // Get a new Identification features helper @@ -24,7 +25,8 @@ func NewIdentification( } i := &Identification{ - Feature: feature, + Feature: feature, + IdentificationCommon: internal.NewRemoteIdentification(feature.featureRemote), } return i, nil @@ -34,13 +36,3 @@ func NewIdentification( func (i *Identification) RequestValues() (*model.MsgCounterType, error) { return i.requestData(model.FunctionTypeIdentificationListData, nil, nil) } - -// return current values for Identification -func (i *Identification) GetValues() ([]model.IdentificationDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.IdentificationListDataType](i.featureRemote, model.FunctionTypeIdentificationListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.IdentificationData, nil -} diff --git a/features/identification_test.go b/features/client/identification_test.go similarity index 60% rename from features/identification_test.go rename to features/client/identification_test.go index b1a97a0e..421b8d67 100644 --- a/features/identification_test.go +++ b/features/client/identification_test.go @@ -1,10 +1,9 @@ -package features_test +package client_test import ( "testing" - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" + features "github.com/enbility/eebus-go/features/client" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" @@ -57,29 +56,3 @@ func (s *IdentificationSuite) Test_RequestValues() { assert.Nil(s.T(), err) assert.NotNil(s.T(), counter) } - -func (s *IdentificationSuite) Test_GetValues() { - data, err := s.identification.GetValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.identification.GetValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *IdentificationSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.IdentificationListDataType{ - IdentificationData: []model.IdentificationDataType{ - { - IdentificationId: util.Ptr(model.IdentificationIdType(0)), - IdentificationType: util.Ptr(model.IdentificationTypeTypeEui64), - IdentificationValue: util.Ptr(model.IdentificationValueType("test")), - }, - }, - } - rF.UpdateData(model.FunctionTypeIdentificationListData, fData, nil, nil) -} diff --git a/features/incentivetable.go b/features/client/incentivetable.go similarity index 56% rename from features/incentivetable.go rename to features/client/incentivetable.go index 9e0d7eb7..1300fabe 100644 --- a/features/incentivetable.go +++ b/features/client/incentivetable.go @@ -1,14 +1,16 @@ -package features +package client import ( "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" ) type IncentiveTable struct { *Feature + + *internal.IncentiveTableCommon } // Get a new IncentiveTable features helper @@ -24,12 +26,15 @@ func NewIncentiveTable( } i := &IncentiveTable{ - Feature: feature, + Feature: feature, + IncentiveTableCommon: internal.NewRemoteIncentiveTable(feature.featureRemote), } return i, nil } +var _ api.IncentiveTableClientInterface = (*IncentiveTable)(nil) + // request FunctionTypeIncentiveTableDescriptionData from a remote entity func (i *IncentiveTable) RequestDescriptions() (*model.MsgCounterType, error) { return i.requestData(model.FunctionTypeIncentiveTableDescriptionData, nil, nil) @@ -47,83 +52,32 @@ func (i *IncentiveTable) RequestValues() (*model.MsgCounterType, error) { // write incentivetable descriptions // returns an error if this failed -func (i *IncentiveTable) WriteValues(data []model.IncentiveTableType) (*model.MsgCounterType, error) { +func (i *IncentiveTable) WriteDescriptions(data []model.IncentiveTableDescriptionType) (*model.MsgCounterType, error) { if len(data) == 0 { return nil, api.ErrMissingData } cmd := model.CmdType{ - IncentiveTableData: &model.IncentiveTableDataType{ - IncentiveTable: data, + IncentiveTableDescriptionData: &model.IncentiveTableDescriptionDataType{ + IncentiveTableDescription: data, }, } return i.remoteDevice.Sender().Write(i.featureLocal.Address(), i.featureRemote.Address(), cmd) } -// return current values for Time Series -func (i *IncentiveTable) GetValues() ([]model.IncentiveTableType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.IncentiveTableDataType](i.featureRemote, model.FunctionTypeIncentiveTableData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.IncentiveTable, nil -} - // write incentivetable descriptions // returns an error if this failed -func (i *IncentiveTable) WriteDescriptions(data []model.IncentiveTableDescriptionType) (*model.MsgCounterType, error) { +func (i *IncentiveTable) WriteValues(data []model.IncentiveTableType) (*model.MsgCounterType, error) { if len(data) == 0 { return nil, api.ErrMissingData } cmd := model.CmdType{ - IncentiveTableDescriptionData: &model.IncentiveTableDescriptionDataType{ - IncentiveTableDescription: data, + IncentiveTableData: &model.IncentiveTableDataType{ + IncentiveTable: data, }, } return i.remoteDevice.Sender().Write(i.featureLocal.Address(), i.featureRemote.Address(), cmd) } - -// return list of descriptions -func (i *IncentiveTable) GetDescriptions() ([]model.IncentiveTableDescriptionType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.IncentiveTableDescriptionDataType](i.featureRemote, model.FunctionTypeIncentiveTableDescriptionData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.IncentiveTableDescription, nil -} - -// return list of descriptions -func (i *IncentiveTable) GetDescriptionsForScope(scope model.ScopeTypeType) ([]model.IncentiveTableDescriptionType, error) { - data, err := i.GetDescriptions() - if err != nil { - return nil, err - } - - var result []model.IncentiveTableDescriptionType - for _, item := range data { - if item.TariffDescription != nil && item.TariffDescription.ScopeType != nil && *item.TariffDescription.ScopeType == scope { - result = append(result, item) - } - } - - if len(result) == 0 { - return nil, api.ErrDataNotAvailable - } - - return result, nil -} - -// return list of constraints -func (i *IncentiveTable) GetConstraints() ([]model.IncentiveTableConstraintsType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.IncentiveTableConstraintsDataType](i.featureRemote, model.FunctionTypeIncentiveTableConstraintsData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.IncentiveTableConstraints, nil -} diff --git a/features/incentivetable_test.go b/features/client/incentivetable_test.go similarity index 52% rename from features/incentivetable_test.go rename to features/client/incentivetable_test.go index c74aab6f..763a9472 100644 --- a/features/incentivetable_test.go +++ b/features/client/incentivetable_test.go @@ -1,9 +1,9 @@ -package features_test +package client_test import ( "testing" - "github.com/enbility/eebus-go/features" + features "github.com/enbility/eebus-go/features/client" "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" @@ -123,18 +123,6 @@ func (s *IncentiveTableSuite) Test_WriteValues() { assert.NotNil(s.T(), counter) } -func (s *IncentiveTableSuite) Test_GetValues() { - data, err := s.incentiveTable.GetValues() - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0, len(data)) - - s.addData() - - data, err = s.incentiveTable.GetValues() - assert.Nil(s.T(), err) - assert.NotEqual(s.T(), nil, data) -} - func (s *IncentiveTableSuite) Test_WriteDescriptions() { counter, err := s.incentiveTable.WriteDescriptions(nil) assert.NotNil(s.T(), err) @@ -179,123 +167,3 @@ func (s *IncentiveTableSuite) Test_WriteDescriptions() { assert.Nil(s.T(), err) assert.NotNil(s.T(), counter) } - -func (s *IncentiveTableSuite) Test_GetDescriptions() { - data, err := s.incentiveTable.GetDescriptions() - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0, len(data)) - - s.addDescription() - - data, err = s.incentiveTable.GetDescriptions() - assert.Nil(s.T(), err) - assert.NotEqual(s.T(), nil, data) -} - -func (s *IncentiveTableSuite) Test_GetDescriptionsForScope() { - scope := model.ScopeTypeTypeSimpleIncentiveTable - data, err := s.incentiveTable.GetDescriptionsForScope(scope) - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0, len(data)) - - s.addDescription() - - data, err = s.incentiveTable.GetDescriptionsForScope(scope) - assert.Nil(s.T(), err) - assert.NotEqual(s.T(), nil, data) -} - -func (s *IncentiveTableSuite) Test_GetConstraints() { - data, err := s.incentiveTable.GetConstraints() - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0, len(data)) - - s.addConstraints() - - data, err = s.incentiveTable.GetConstraints() - assert.Nil(s.T(), err) - assert.NotEqual(s.T(), nil, data) -} - -// helpers - -func (s *IncentiveTableSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - - fData := &model.IncentiveTableDataType{ - IncentiveTable: []model.IncentiveTableType{ - { - Tariff: &model.TariffDataType{ - TariffId: util.Ptr(model.TariffIdType(0)), - }, - IncentiveSlot: []model.IncentiveTableIncentiveSlotType{ - { - TimeInterval: &model.TimeTableDataType{}, - }, - }, - }, - }, - } - rF.UpdateData(model.FunctionTypeIncentiveTableData, fData, nil, nil) -} - -func (s *IncentiveTableSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.IncentiveTableDescriptionDataType{ - IncentiveTableDescription: []model.IncentiveTableDescriptionType{ - { - TariffDescription: &model.TariffDescriptionDataType{ - TariffId: util.Ptr(model.TariffIdType(0)), - TariffWriteable: util.Ptr(true), - UpdateRequired: util.Ptr(true), - ScopeType: util.Ptr(model.ScopeTypeTypeSimpleIncentiveTable), - }, - Tier: []model.IncentiveTableDescriptionTierType{ - { - TierDescription: &model.TierDescriptionDataType{ - TierId: util.Ptr(model.TierIdType(0)), - TierType: util.Ptr(model.TierTypeTypeDynamicCost), - }, - BoundaryDescription: []model.TierBoundaryDescriptionDataType{ - { - BoundaryId: util.Ptr(model.TierBoundaryIdType(0)), - BoundaryType: util.Ptr(model.TierBoundaryTypeTypePowerBoundary), - BoundaryUnit: util.Ptr(model.UnitOfMeasurementTypeW), - }, - }, - IncentiveDescription: []model.IncentiveDescriptionDataType{ - { - IncentiveId: util.Ptr(model.IncentiveIdType(0)), - IncentiveType: util.Ptr(model.IncentiveTypeTypeAbsoluteCost), - Currency: util.Ptr(model.CurrencyTypeEur), - }, - }, - }, - }, - }, - }, - } - rF.UpdateData(model.FunctionTypeIncentiveTableDescriptionData, fData, nil, nil) -} - -func (s *IncentiveTableSuite) addConstraints() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.IncentiveTableConstraintsDataType{ - IncentiveTableConstraints: []model.IncentiveTableConstraintsType{ - { - Tariff: &model.TariffDataType{ - TariffId: util.Ptr(model.TariffIdType(0)), - }, - TariffConstraints: &model.TariffOverallConstraintsDataType{ - MaxTiersPerTariff: util.Ptr(model.TierCountType(3)), - MaxBoundariesPerTier: util.Ptr(model.TierBoundaryCountType(1)), - MaxIncentivesPerTier: util.Ptr(model.IncentiveCountType(3)), - }, - IncentiveSlotConstraints: &model.TimeTableConstraintsDataType{ - SlotCountMax: util.Ptr(model.TimeSlotCountType(24)), - }, - }, - }, - } - rF.UpdateData(model.FunctionTypeIncentiveTableConstraintsData, fData, nil, nil) -} diff --git a/features/client/loadcontrol.go b/features/client/loadcontrol.go new file mode 100644 index 00000000..fac27c39 --- /dev/null +++ b/features/client/loadcontrol.go @@ -0,0 +1,70 @@ +package client + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type LoadControl struct { + *Feature + + *internal.LoadControlCommon +} + +// Get a new LoadControl features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewLoadControl( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*LoadControl, error) { + feature, err := NewFeature(model.FeatureTypeTypeLoadControl, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + lc := &LoadControl{ + Feature: feature, + LoadControlCommon: internal.NewRemoteLoadControl(feature.featureRemote), + } + + return lc, nil +} + +var _ api.LoadControlClientInterface = (*LoadControl)(nil) + +// request FunctionTypeLoadControlLimitDescriptionListData from a remote device +func (l *LoadControl) RequestLimitDescriptions() (*model.MsgCounterType, error) { + return l.requestData(model.FunctionTypeLoadControlLimitDescriptionListData, nil, nil) +} + +// request FunctionTypeLoadControlLimitConstraintsListData from a remote device +func (l *LoadControl) RequestLimitConstraints() (*model.MsgCounterType, error) { + return l.requestData(model.FunctionTypeLoadControlLimitConstraintsListData, nil, nil) +} + +// request FunctionTypeLoadControlLimitListData from a remote device +func (l *LoadControl) RequestLimitData() (*model.MsgCounterType, error) { + return l.requestData(model.FunctionTypeLoadControlLimitListData, nil, nil) +} + +// write load control limits +// returns an error if this failed +func (l *LoadControl) WriteLimitData(data []model.LoadControlLimitDataType) (*model.MsgCounterType, error) { + if len(data) == 0 { + return nil, api.ErrMissingData + } + + cmd := model.CmdType{ + Function: util.Ptr(model.FunctionTypeLoadControlLimitListData), + Filter: []model.FilterType{*model.NewFilterTypePartial()}, + LoadControlLimitListData: &model.LoadControlLimitListDataType{ + LoadControlLimitData: data, + }, + } + + return l.remoteDevice.Sender().Write(l.featureLocal.Address(), l.featureRemote.Address(), cmd) +} diff --git a/features/client/loadcontrol_test.go b/features/client/loadcontrol_test.go new file mode 100644 index 00000000..99d67004 --- /dev/null +++ b/features/client/loadcontrol_test.go @@ -0,0 +1,94 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + "github.com/enbility/eebus-go/util" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestLoadControlSuite(t *testing.T) { + suite.Run(t, new(LoadControlSuite)) +} + +type LoadControlSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + loadControl *features.LoadControl + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*LoadControlSuite)(nil) + +func (s *LoadControlSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeLoadControl, + functions: []model.FunctionType{ + model.FunctionTypeLoadControlLimitDescriptionListData, + model.FunctionTypeLoadControlLimitConstraintsListData, + model.FunctionTypeLoadControlLimitListData, + }, + }, + }, + ) + + var err error + s.loadControl, err = features.NewLoadControl(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.loadControl) +} + +func (s *LoadControlSuite) Test_RequestLimitDescription() { + counter, err := s.loadControl.RequestLimitDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *LoadControlSuite) Test_RequestLimitConstraints() { + counter, err := s.loadControl.RequestLimitConstraints() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *LoadControlSuite) Test_RequestLimits() { + counter, err := s.loadControl.RequestLimitData() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *LoadControlSuite) Test_WriteLimitValues() { + counter, err := s.loadControl.WriteLimitData(nil) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data := []model.LoadControlLimitDataType{} + counter, err = s.loadControl.WriteLimitData(data) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data = []model.LoadControlLimitDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + Value: model.NewScaledNumberType(10), + }, + } + counter, err = s.loadControl.WriteLimitData(data) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/client/measurement.go b/features/client/measurement.go new file mode 100644 index 00000000..5ad960e7 --- /dev/null +++ b/features/client/measurement.go @@ -0,0 +1,48 @@ +package client + +import ( + "github.com/enbility/eebus-go/features/internal" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type Measurement struct { + *Feature + + *internal.MeasurementCommon +} + +// Get a new Measurement features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewMeasurement( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*Measurement, error) { + feature, err := NewFeature(model.FeatureTypeTypeMeasurement, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + m := &Measurement{ + Feature: feature, + MeasurementCommon: internal.NewRemoteMeasurement(feature.featureRemote), + } + + return m, nil +} + +// request FunctionTypeMeasurementDescriptionListData from a remote device +func (m *Measurement) RequestDescriptions() (*model.MsgCounterType, error) { + return m.requestData(model.FunctionTypeMeasurementDescriptionListData, nil, nil) +} + +// request FunctionTypeMeasurementConstraintsListData from a remote entity +func (m *Measurement) RequestConstraints() (*model.MsgCounterType, error) { + return m.requestData(model.FunctionTypeMeasurementConstraintsListData, nil, nil) +} + +// request FunctionTypeMeasurementListData from a remote entity +func (m *Measurement) RequestData() (*model.MsgCounterType, error) { + return m.requestData(model.FunctionTypeMeasurementListData, nil, nil) +} diff --git a/features/client/measurement_test.go b/features/client/measurement_test.go new file mode 100644 index 00000000..e34372c7 --- /dev/null +++ b/features/client/measurement_test.go @@ -0,0 +1,80 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestMeasurementSuite(t *testing.T) { + suite.Run(t, new(MeasurementSuite)) +} + +type MeasurementSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + measurement *features.Measurement + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*MeasurementSuite)(nil) + +func (s *MeasurementSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeMeasurement, + functions: []model.FunctionType{ + model.FunctionTypeMeasurementDescriptionListData, + model.FunctionTypeMeasurementConstraintsListData, + model.FunctionTypeMeasurementListData, + }, + }, + { + featureType: model.FeatureTypeTypeElectricalConnection, + functions: []model.FunctionType{ + model.FunctionTypeElectricalConnectionDescriptionListData, + model.FunctionTypeElectricalConnectionParameterDescriptionListData, + model.FunctionTypeElectricalConnectionPermittedValueSetListData, + }, + }, + }, + ) + + var err error + s.measurement, err = features.NewMeasurement(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.measurement) +} + +func (s *MeasurementSuite) Test_RequestDescriptions() { + msgCounter, err := s.measurement.RequestDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), msgCounter) +} + +func (s *MeasurementSuite) Test_RequestConstraints() { + msgCounter, err := s.measurement.RequestConstraints() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), msgCounter) +} + +func (s *MeasurementSuite) Test_RequestData() { + counter, err := s.measurement.RequestData() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/smartenergymanagementps.go b/features/client/smartenergymanagementps.go similarity index 66% rename from features/smartenergymanagementps.go rename to features/client/smartenergymanagementps.go index 8d90a08d..0d5b542b 100644 --- a/features/smartenergymanagementps.go +++ b/features/client/smartenergymanagementps.go @@ -1,15 +1,17 @@ -package features +package client import ( "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" ) type SmartEnergyManagementPs struct { *Feature + + *internal.SmartEnergyManagementPsCommon } // Get a new Identification features helper @@ -25,20 +27,21 @@ func NewSmartEnergyManagementPs( } i := &SmartEnergyManagementPs{ - Feature: feature, + Feature: feature, + SmartEnergyManagementPsCommon: internal.NewRemoteSmartEnergyManagementPs(feature.featureRemote), } return i, nil } // request FunctionTypeSmartEnergyManagementPsData from a remote entity -func (i *SmartEnergyManagementPs) RequestValues() (*model.MsgCounterType, error) { +func (i *SmartEnergyManagementPs) RequestData() (*model.MsgCounterType, error) { return i.requestData(model.FunctionTypeSmartEnergyManagementPsData, nil, nil) } // write SmartEnergyManagementPsData // returns an error if this failed -func (l *SmartEnergyManagementPs) WriteValues(data *model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error) { +func (l *SmartEnergyManagementPs) WriteData(data *model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error) { if data == nil { return nil, api.ErrMissingData } @@ -51,13 +54,3 @@ func (l *SmartEnergyManagementPs) WriteValues(data *model.SmartEnergyManagementP return l.remoteDevice.Sender().Write(l.featureLocal.Address(), l.featureRemote.Address(), cmd) } - -// return current values for FunctionTypeSmartEnergyManagementPsData -func (i *SmartEnergyManagementPs) GetValues() (*model.SmartEnergyManagementPsDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.SmartEnergyManagementPsDataType](i.featureRemote, model.FunctionTypeSmartEnergyManagementPsData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data, nil -} diff --git a/features/smartenergymanagementps_test.go b/features/client/smartenergymanagementps_test.go similarity index 60% rename from features/smartenergymanagementps_test.go rename to features/client/smartenergymanagementps_test.go index fcca328f..42586381 100644 --- a/features/smartenergymanagementps_test.go +++ b/features/client/smartenergymanagementps_test.go @@ -1,10 +1,9 @@ -package features_test +package client_test import ( "testing" - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" + features "github.com/enbility/eebus-go/features/client" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" @@ -52,14 +51,14 @@ func (s *SmartEnergyManagementPsSuite) BeforeTest(suiteName, testName string) { assert.NotNil(s.T(), s.smartenergymgmtps) } -func (s *SmartEnergyManagementPsSuite) Test_RequestValues() { - counter, err := s.smartenergymgmtps.RequestValues() +func (s *SmartEnergyManagementPsSuite) Test_RequestData() { + counter, err := s.smartenergymgmtps.RequestData() assert.Nil(s.T(), err) assert.NotNil(s.T(), counter) } -func (s *SmartEnergyManagementPsSuite) Test_WriteValues() { - counter, err := s.smartenergymgmtps.WriteValues(nil) +func (s *SmartEnergyManagementPsSuite) Test_WriteData() { + counter, err := s.smartenergymgmtps.WriteData(nil) assert.NotNil(s.T(), err) assert.Nil(s.T(), counter) @@ -67,29 +66,7 @@ func (s *SmartEnergyManagementPsSuite) Test_WriteValues() { NodeScheduleInformation: &model.PowerSequenceNodeScheduleInformationDataType{}, Alternatives: []model.SmartEnergyManagementPsAlternativesType{}, } - counter, err = s.smartenergymgmtps.WriteValues(data) + counter, err = s.smartenergymgmtps.WriteData(data) assert.Nil(s.T(), err) assert.NotNil(s.T(), counter) } - -func (s *SmartEnergyManagementPsSuite) Test_GetValues() { - value, err := s.smartenergymgmtps.GetValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), value) - - s.addData() - - value, err = s.smartenergymgmtps.GetValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) -} - -func (s *SmartEnergyManagementPsSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - - fData := &model.SmartEnergyManagementPsDataType{ - NodeScheduleInformation: &model.PowerSequenceNodeScheduleInformationDataType{}, - Alternatives: []model.SmartEnergyManagementPsAlternativesType{}, - } - rF.UpdateData(model.FunctionTypeSmartEnergyManagementPsData, fData, nil, nil) -} diff --git a/features/client/timeseries.go b/features/client/timeseries.go new file mode 100644 index 00000000..aef6ccba --- /dev/null +++ b/features/client/timeseries.go @@ -0,0 +1,67 @@ +package client + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type TimeSeries struct { + *Feature + + *internal.TimeSeriesCommon +} + +// Get a new TimeSeries features helper +// +// - The feature on the local entity has to be of role client +// - The feature on the remote entity has to be of role server +func NewTimeSeries( + localEntity spineapi.EntityLocalInterface, + remoteEntity spineapi.EntityRemoteInterface) (*TimeSeries, error) { + feature, err := NewFeature(model.FeatureTypeTypeTimeSeries, localEntity, remoteEntity) + if err != nil { + return nil, err + } + + t := &TimeSeries{ + Feature: feature, + TimeSeriesCommon: internal.NewRemoteTimeSeries(feature.featureRemote), + } + + return t, nil +} + +var _ api.TimeSeriesClientInterface = (*TimeSeries)(nil) + +// request FunctionTypeTimeSeriesDescriptionListData from a remote entity +func (t *TimeSeries) RequestDescriptions() (*model.MsgCounterType, error) { + return t.requestData(model.FunctionTypeTimeSeriesDescriptionListData, nil, nil) +} + +// request FunctionTypeTimeSeriesConstraintsListData from a remote entity +func (t *TimeSeries) RequestConstraints() (*model.MsgCounterType, error) { + return t.requestData(model.FunctionTypeTimeSeriesConstraintsListData, nil, nil) +} + +// request FunctionTypeTimeSeriesListData from a remote device +func (t *TimeSeries) RequestData() (*model.MsgCounterType, error) { + return t.requestData(model.FunctionTypeTimeSeriesListData, nil, nil) +} + +// write Time Series values +// returns an error if this failed +func (t *TimeSeries) WriteData(data []model.TimeSeriesDataType) (*model.MsgCounterType, error) { + if len(data) == 0 { + return nil, api.ErrMissingData + } + + cmd := model.CmdType{ + TimeSeriesListData: &model.TimeSeriesListDataType{ + TimeSeriesData: data, + }, + } + + return t.remoteDevice.Sender().Write(t.featureLocal.Address(), t.featureRemote.Address(), cmd) +} diff --git a/features/client/timeseries_test.go b/features/client/timeseries_test.go new file mode 100644 index 00000000..71762690 --- /dev/null +++ b/features/client/timeseries_test.go @@ -0,0 +1,93 @@ +package client_test + +import ( + "testing" + + features "github.com/enbility/eebus-go/features/client" + "github.com/enbility/eebus-go/util" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/suite" +) + +func TestTimeSeriesSuite(t *testing.T) { + suite.Run(t, new(TimeSeriesSuite)) +} + +type TimeSeriesSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + timeSeries *features.TimeSeries + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*TimeSeriesSuite)(nil) + +func (s *TimeSeriesSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *TimeSeriesSuite) BeforeTest(suiteName, testName string) { + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + s, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeTimeSeries, + functions: []model.FunctionType{ + model.FunctionTypeTimeSeriesConstraintsListData, + model.FunctionTypeTimeSeriesDescriptionListData, + model.FunctionTypeTimeSeriesListData, + }, + }, + }, + ) + + var err error + s.timeSeries, err = features.NewTimeSeries(s.localEntity, s.remoteEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.timeSeries) +} + +func (s *TimeSeriesSuite) Test_RequestDescription() { + msgCounter, err := s.timeSeries.RequestDescriptions() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), msgCounter) +} + +func (s *TimeSeriesSuite) Test_RequestConstraints() { + msgCounter, err := s.timeSeries.RequestConstraints() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), msgCounter) +} + +func (s *TimeSeriesSuite) Test_RequestData() { + counter, err := s.timeSeries.RequestData() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} + +func (s *TimeSeriesSuite) Test_WriteData() { + counter, err := s.timeSeries.WriteData(nil) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data := []model.TimeSeriesDataType{} + counter, err = s.timeSeries.WriteData(data) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), counter) + + data = []model.TimeSeriesDataType{ + { + TimeSeriesId: util.Ptr(model.TimeSeriesIdType(1)), + }, + } + counter, err = s.timeSeries.WriteData(data) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), counter) +} diff --git a/features/deviceconfiguration.go b/features/deviceconfiguration.go deleted file mode 100644 index 8275ba62..00000000 --- a/features/deviceconfiguration.go +++ /dev/null @@ -1,157 +0,0 @@ -package features - -import ( - "github.com/enbility/eebus-go/api" - "github.com/enbility/eebus-go/util" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type DeviceConfiguration struct { - *Feature -} - -// Get a new DeviceConfiguration features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewDeviceConfiguration( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*DeviceConfiguration, error) { - feature, err := NewFeature(model.FeatureTypeTypeDeviceConfiguration, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - dc := &DeviceConfiguration{ - Feature: feature, - } - - return dc, nil -} - -// request DeviceConfiguration data from a remote entity -func (d *DeviceConfiguration) RequestDescriptions() (*model.MsgCounterType, error) { - return d.requestData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, nil, nil) -} - -// request DeviceConfigurationKeyValueListDataType from a remote entity -func (d *DeviceConfiguration) RequestKeyValues() (*model.MsgCounterType, error) { - return d.requestData(model.FunctionTypeDeviceConfigurationKeyValueListData, nil, nil) -} - -// return current descriptions for Device Configuration -func (d *DeviceConfiguration) GetDescriptions() ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.DeviceConfigurationKeyValueDescriptionListDataType](d.featureRemote, model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.DeviceConfigurationKeyValueDescriptionData, nil -} - -// returns the description of a provided key name -func (d *DeviceConfiguration) GetDescriptionForKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) { - descriptions, err := d.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range descriptions { - if item.KeyId != nil && *item.KeyId == keyId { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} - -// returns the description of a provided key name -// returns an error if the key name was not found -func (d *DeviceConfiguration) GetDescriptionForKeyName(keyName model.DeviceConfigurationKeyNameType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) { - descriptions, err := d.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range descriptions { - if item.KeyId != nil && - item.KeyName != nil && - *item.KeyName == keyName { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} - -// return current values for Device Configuration -func (d *DeviceConfiguration) GetKeyValues() ([]model.DeviceConfigurationKeyValueDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.DeviceConfigurationKeyValueListDataType](d.featureRemote, model.FunctionTypeDeviceConfigurationKeyValueListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.DeviceConfigurationKeyValueData, nil -} - -// write key values -// returns an error if this failed -func (d *DeviceConfiguration) WriteKeyValues(data []model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error) { - if len(data) == 0 { - return nil, api.ErrMissingData - } - - cmd := model.CmdType{ - Function: util.Ptr(model.FunctionTypeDeviceConfigurationKeyValueListData), - Filter: []model.FilterType{*model.NewFilterTypePartial()}, - DeviceConfigurationKeyValueListData: &model.DeviceConfigurationKeyValueListDataType{ - DeviceConfigurationKeyValueData: data, - }, - } - - return d.remoteDevice.Sender().Write(d.featureLocal.Address(), d.featureRemote.Address(), cmd) -} - -// return a pointer value for a given key and value type -func (d *DeviceConfiguration) GetKeyValueForKeyName(keyname model.DeviceConfigurationKeyNameType, valueType model.DeviceConfigurationKeyValueTypeType) (any, error) { - values, err := d.GetKeyValues() - if err != nil { - return nil, err - } - - for _, item := range values { - if item.KeyId == nil || item.Value == nil { - continue - } - - desc, err := d.GetDescriptionForKeyId(*item.KeyId) - if err != nil { - continue - } - - if desc.KeyName != nil && *desc.KeyName == keyname { - switch valueType { - case model.DeviceConfigurationKeyValueTypeTypeBoolean: - return item.Value.Boolean, nil - case model.DeviceConfigurationKeyValueTypeTypeDate: - return item.Value.Date, nil - case model.DeviceConfigurationKeyValueTypeTypeDateTime: - return item.Value.DateTime, nil - case model.DeviceConfigurationKeyValueTypeTypeDuration: - return item.Value.Duration, nil - case model.DeviceConfigurationKeyValueTypeTypeString: - return item.Value.String, nil - case model.DeviceConfigurationKeyValueTypeTypeTime: - return item.Value.Time, nil - case model.DeviceConfigurationKeyValueTypeTypeScaledNumber: - return item.Value.ScaledNumber, nil - default: - return nil, api.ErrDataNotAvailable - } - } - } - - return nil, api.ErrDataNotAvailable -} diff --git a/features/deviceconfiguration_test.go b/features/deviceconfiguration_test.go deleted file mode 100644 index 7def2cb4..00000000 --- a/features/deviceconfiguration_test.go +++ /dev/null @@ -1,281 +0,0 @@ -package features_test - -import ( - "testing" - "time" - - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" - shipmocks "github.com/enbility/ship-go/mocks" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/mock" - "github.com/stretchr/testify/suite" -) - -func TestDeviceConfigurationSuite(t *testing.T) { - suite.Run(t, new(DeviceConfigurationSuite)) -} - -type DeviceConfigurationSuite struct { - suite.Suite - - localEntity spineapi.EntityLocalInterface - remoteEntity spineapi.EntityRemoteInterface - - deviceConfiguration *features.DeviceConfiguration -} - -func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { - mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) - mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() - - s.localEntity, s.remoteEntity = setupFeatures( - s.T(), - mockWriter, - []featureFunctions{ - { - featureType: model.FeatureTypeTypeDeviceConfiguration, - functions: []model.FunctionType{ - model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, - model.FunctionTypeDeviceConfigurationKeyValueListData, - }, - }, - }, - ) - - var err error - s.deviceConfiguration, err = features.NewDeviceConfiguration(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.deviceConfiguration) -} - -func (s *DeviceConfigurationSuite) Test_RequestDescriptions() { - counter, err := s.deviceConfiguration.RequestDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *DeviceConfigurationSuite) Test_RequestKeyValueList() { - counter, err := s.deviceConfiguration.RequestKeyValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *DeviceConfigurationSuite) Test_GetDescriptionForKeyId() { - keyId := model.DeviceConfigurationKeyIdType(0) - desc, err := s.deviceConfiguration.GetDescriptionForKeyId(keyId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), desc) - - s.addDescription() - - desc, err = s.deviceConfiguration.GetDescriptionForKeyId(keyId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), desc) -} - -func (s *DeviceConfigurationSuite) Test_GetDescriptionForKeyName() { - desc, err := s.deviceConfiguration.GetDescriptionForKeyName(model.DeviceConfigurationKeyNameTypeCommunicationsStandard) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), desc) - - s.addDescription() - - desc, err = s.deviceConfiguration.GetDescriptionForKeyName(model.DeviceConfigurationKeyNameTypeCommunicationsStandard) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), desc) -} - -func (s *DeviceConfigurationSuite) Test_GetValueForKey() { - key := model.DeviceConfigurationKeyNameTypeCommunicationsStandard - valueType := model.DeviceConfigurationKeyValueTypeTypeString - - value, err := s.deviceConfiguration.GetKeyValueForKeyName(key, valueType) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), value) - - s.addDescription() - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(key, valueType) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), value) - - s.addData() - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(key, valueType) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported, model.DeviceConfigurationKeyValueTypeTypeBoolean) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor, model.DeviceConfigurationKeyValueTypeTypeScaledNumber) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeAzimuth, model.DeviceConfigurationKeyValueTypeTypeDate) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeBatteryType, model.DeviceConfigurationKeyValueTypeTypeDateTime) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeTimeToAcDischargePowerMax, model.DeviceConfigurationKeyValueTypeTypeDuration) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable, model.DeviceConfigurationKeyValueTypeTypeTime) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable, model.DeviceConfigurationKeyValueTypeType("invalid")) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), value) - - value, err = s.deviceConfiguration.GetKeyValueForKeyName(model.DeviceConfigurationKeyNameType("invalid"), model.DeviceConfigurationKeyValueTypeType("invalid")) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), value) -} - -func (s *DeviceConfigurationSuite) Test_GetValues() { - data, err := s.deviceConfiguration.GetKeyValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.deviceConfiguration.GetKeyValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.deviceConfiguration.GetKeyValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *DeviceConfigurationSuite) Test_WriteValues() { - counter, err := s.deviceConfiguration.WriteKeyValues(nil) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data := []model.DeviceConfigurationKeyValueDataType{} - counter, err = s.deviceConfiguration.WriteKeyValues(data) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data = []model.DeviceConfigurationKeyValueDataType{ - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), - Value: &model.DeviceConfigurationKeyValueValueType{ - ScaledNumber: model.NewScaledNumberType(10), - }, - }, - } - counter, err = s.deviceConfiguration.WriteKeyValues(data) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -// helper - -func (s *DeviceConfigurationSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.DeviceConfigurationKeyValueDescriptionListDataType{ - DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{ - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeCommunicationsStandard), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeString), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber), - Unit: util.Ptr(model.UnitOfMeasurementTypepct), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(3)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeAzimuth), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDate), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(4)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeBatteryType), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDateTime), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(5)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeTimeToAcDischargePowerMax), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDuration), - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(6)), - KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable), - ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeTime), - }, - }, - } - rF.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, fData, nil, nil) -} - -func (s *DeviceConfigurationSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.DeviceConfigurationKeyValueListDataType{ - DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{ - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), - Value: &model.DeviceConfigurationKeyValueValueType{ - String: util.Ptr(model.DeviceConfigurationKeyValueStringType("test")), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), - Value: &model.DeviceConfigurationKeyValueValueType{ - Boolean: util.Ptr(true), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), - Value: &model.DeviceConfigurationKeyValueValueType{ - ScaledNumber: model.NewScaledNumberType(50), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(3)), - Value: &model.DeviceConfigurationKeyValueValueType{ - Date: model.NewDateType("01.01.2023"), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(4)), - Value: &model.DeviceConfigurationKeyValueValueType{ - DateTime: model.NewDateTimeTypeFromTime(time.Now()), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(5)), - Value: &model.DeviceConfigurationKeyValueValueType{ - Duration: model.NewDurationType(time.Second * 4), - }, - }, - { - KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(6)), - Value: &model.DeviceConfigurationKeyValueValueType{ - Time: model.NewTimeType("13:05"), - }, - }, - }, - } - rF.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, fData, nil, nil) -} diff --git a/features/devicediagnosis.go b/features/devicediagnosis.go deleted file mode 100644 index 7966d067..00000000 --- a/features/devicediagnosis.go +++ /dev/null @@ -1,74 +0,0 @@ -package features - -import ( - "time" - - "github.com/enbility/eebus-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type DeviceDiagnosis struct { - *Feature -} - -// Get a new DeviceDiagnosis features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewDeviceDiagnosis( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*DeviceDiagnosis, error) { - feature, err := NewFeature(model.FeatureTypeTypeDeviceDiagnosis, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - dd := &DeviceDiagnosis{ - Feature: feature, - } - - return dd, nil -} - -// request DeviceDiagnosisStateData from a remote entity -func (d *DeviceDiagnosis) RequestState() (*model.MsgCounterType, error) { - return d.requestData(model.FunctionTypeDeviceDiagnosisStateData, nil, nil) -} - -// get the current diagnosis state for an device entity -func (d *DeviceDiagnosis) GetState() (*model.DeviceDiagnosisStateDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.DeviceDiagnosisStateDataType](d.featureRemote, model.FunctionTypeDeviceDiagnosisStateData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data, nil -} - -func (d *DeviceDiagnosis) SetLocalState(operatingState *model.DeviceDiagnosisStateDataType) { - d.featureLocal.SetData(model.FunctionTypeDeviceDiagnosisStateData, operatingState) -} - -// request FunctionTypeDeviceDiagnosisHeartbeatData from a remote device -func (d *DeviceDiagnosis) RequestHeartbeat() (*model.MsgCounterType, error) { - return d.requestData(model.FunctionTypeDeviceDiagnosisHeartbeatData, nil, nil) -} - -// check if the currently available heartbeat data is within a time duration -func (d *DeviceDiagnosis) IsHeartbeatWithinDuration(duration time.Duration) bool { - data, err := spine.RemoteFeatureDataCopyOfType[*model.DeviceDiagnosisHeartbeatDataType](d.featureRemote, model.FunctionTypeDeviceDiagnosisHeartbeatData) - if err != nil || data == nil || data.Timestamp == nil { - return false - } - - timeValue, err := data.Timestamp.GetTime() - if err != nil { - return false - } - - diff := time.Now().UTC().Add(-1 * duration) - - return diff.Compare(timeValue.Local()) <= 0 -} diff --git a/features/devicediagnosis_test.go b/features/devicediagnosis_test.go deleted file mode 100644 index 08d0dcff..00000000 --- a/features/devicediagnosis_test.go +++ /dev/null @@ -1,123 +0,0 @@ -package features_test - -import ( - "testing" - "time" - - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" - shipapi "github.com/enbility/ship-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -func TestDeviceDiagnosisSuite(t *testing.T) { - suite.Run(t, new(DeviceDiagnosisSuite)) -} - -type DeviceDiagnosisSuite struct { - suite.Suite - - localEntity spineapi.EntityLocalInterface - remoteEntity spineapi.EntityRemoteInterface - - deviceDiagnosis *features.DeviceDiagnosis - sentMessage []byte -} - -var _ shipapi.ShipConnectionDataWriterInterface = (*DeviceDiagnosisSuite)(nil) - -func (s *DeviceDiagnosisSuite) WriteShipMessageWithPayload(message []byte) { - s.sentMessage = message -} - -func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { - s.localEntity, s.remoteEntity = setupFeatures( - s.T(), - s, - []featureFunctions{ - { - featureType: model.FeatureTypeTypeDeviceDiagnosis, - functions: []model.FunctionType{ - model.FunctionTypeDeviceDiagnosisStateData, - model.FunctionTypeDeviceDiagnosisHeartbeatData, - }, - }, - }, - ) - - var err error - s.deviceDiagnosis, err = features.NewDeviceDiagnosis(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.deviceDiagnosis) -} - -func (s *DeviceDiagnosisSuite) Test_RequestHeartbeat() { - counter, err := s.deviceDiagnosis.RequestHeartbeat() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *DeviceDiagnosisSuite) Test_RequestState() { - counter, err := s.deviceDiagnosis.RequestState() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *DeviceDiagnosisSuite) Test_GetState() { - result, err := s.deviceDiagnosis.GetState() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), result) - - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.DeviceDiagnosisStateDataType{ - OperatingState: util.Ptr(model.DeviceDiagnosisOperatingStateTypeNormalOperation), - PowerSupplyCondition: util.Ptr(model.PowerSupplyConditionTypeGood), - } - rF.UpdateData(model.FunctionTypeDeviceDiagnosisStateData, fData, nil, nil) - - result, err = s.deviceDiagnosis.GetState() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), result) -} - -func (s *DeviceDiagnosisSuite) Test_SetState() { - data := &model.DeviceDiagnosisStateDataType{ - OperatingState: util.Ptr(model.DeviceDiagnosisOperatingStateTypeNormalOperation), - PowerSupplyCondition: util.Ptr(model.PowerSupplyConditionTypeGood), - } - s.deviceDiagnosis.SetLocalState(data) - assert.NotNil(s.T(), s.sentMessage) -} - -func (s *DeviceDiagnosisSuite) Test_IsHeartbeatWithinDuration() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - - result := s.deviceDiagnosis.IsHeartbeatWithinDuration(time.Second * 10) - assert.Equal(s.T(), false, result) - - now := time.Now().UTC() - - data := &model.DeviceDiagnosisHeartbeatDataType{ - HeartbeatCounter: util.Ptr(uint64(1)), - HeartbeatTimeout: model.NewDurationType(time.Second * 4), - } - - rF.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) - - result = s.deviceDiagnosis.IsHeartbeatWithinDuration(time.Second * 10) - assert.Equal(s.T(), false, result) - - data.Timestamp = model.NewAbsoluteOrRelativeTimeTypeFromTime(now) - rF.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) - - result = s.deviceDiagnosis.IsHeartbeatWithinDuration(time.Second * 10) - assert.Equal(s.T(), true, result) - - time.Sleep(time.Second * 2) - - result = s.deviceDiagnosis.IsHeartbeatWithinDuration(time.Second * 1) - assert.Equal(s.T(), false, result) -} diff --git a/features/electricalconnection.go b/features/electricalconnection.go deleted file mode 100644 index 0d35e1de..00000000 --- a/features/electricalconnection.go +++ /dev/null @@ -1,322 +0,0 @@ -package features - -import ( - "github.com/enbility/eebus-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type ElectricalConnection struct { - *Feature -} - -// Get a new ElectricalConnection features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewElectricalConnection( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*ElectricalConnection, error) { - feature, err := NewFeature(model.FeatureTypeTypeElectricalConnection, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - e := &ElectricalConnection{ - Feature: feature, - } - - return e, nil -} - -// request ElectricalConnectionDescriptionListDataType from a remote entity -func (e *ElectricalConnection) RequestDescriptions() (*model.MsgCounterType, error) { - return e.requestData(model.FunctionTypeElectricalConnectionDescriptionListData, nil, nil) -} - -// request FunctionTypeElectricalConnectionParameterDescriptionListData from a remote entity -func (e *ElectricalConnection) RequestParameterDescriptions() (*model.MsgCounterType, error) { - return e.requestData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, nil, nil) -} - -// request FunctionTypeElectricalConnectionPermittedValueSetListData from a remote entity -func (e *ElectricalConnection) RequestPermittedValueSets() (*model.MsgCounterType, error) { - return e.requestData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, nil, nil) -} - -// request FunctionTypeElectricalConnectionCharacteristicListData from a remote entity -func (e *ElectricalConnection) RequestCharacteristics() (*model.MsgCounterType, error) { - return e.requestData(model.FunctionTypeElectricalConnectionCharacteristicListData, nil, nil) -} - -// return list of description for Electrical Connection -func (e *ElectricalConnection) GetDescriptions() ([]model.ElectricalConnectionDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.ElectricalConnectionDescriptionListDataType](e.featureRemote, model.FunctionTypeElectricalConnectionDescriptionListData) - if err != nil { - return nil, api.ErrMetadataNotAvailable - } - - return data.ElectricalConnectionDescriptionData, nil -} - -// return current electrical description for a given measurementId -func (e *ElectricalConnection) GetDescriptionForMeasurementId(measurementId model.MeasurementIdType) (*model.ElectricalConnectionDescriptionDataType, error) { - param, err := e.GetParameterDescriptionForMeasurementId(measurementId) - if err != nil { - return nil, err - } - - descriptions, err := e.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range descriptions { - if item.ElectricalConnectionId == nil || - param.ElectricalConnectionId == nil || - *item.ElectricalConnectionId != *param.ElectricalConnectionId { - continue - } - - return &item, nil - } - - return nil, api.ErrMetadataNotAvailable -} - -// return parameter descriptions for all Electrical Connections -func (e *ElectricalConnection) GetParameterDescriptions() ([]model.ElectricalConnectionParameterDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.ElectricalConnectionParameterDescriptionListDataType](e.featureRemote, model.FunctionTypeElectricalConnectionParameterDescriptionListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.ElectricalConnectionParameterDescriptionData, nil -} - -// return parameter description for a specific scope -func (e *ElectricalConnection) GetParameterDescriptionForScopeType(scope model.ScopeTypeType) (*model.ElectricalConnectionParameterDescriptionDataType, error) { - desc, err := e.GetParameterDescriptions() - if err != nil { - return nil, err - } - - for _, element := range desc { - if element.ScopeType == nil || *element.ScopeType != scope { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return parameter description for a specific parameterId -func (e *ElectricalConnection) GetParameterDescriptionForParameterId(parameterId model.ElectricalConnectionParameterIdType) (*model.ElectricalConnectionParameterDescriptionDataType, error) { - desc, err := e.GetParameterDescriptions() - if err != nil { - return nil, err - } - - for _, element := range desc { - if element.ParameterId == nil || *element.ParameterId != parameterId { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return parameter description for a specific measurementId -func (e *ElectricalConnection) GetParameterDescriptionForMeasurementId(measurementId model.MeasurementIdType) (*model.ElectricalConnectionParameterDescriptionDataType, error) { - desc, err := e.GetParameterDescriptions() - if err != nil { - return nil, err - } - - for _, element := range desc { - if element.MeasurementId == nil || *element.MeasurementId != measurementId { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return parameter description for a specific measurementId -func (e *ElectricalConnection) GetParameterDescriptionForMeasuredPhase(phase model.ElectricalConnectionPhaseNameType) (*model.ElectricalConnectionParameterDescriptionDataType, error) { - desc, err := e.GetParameterDescriptions() - if err != nil { - return nil, err - } - - for _, element := range desc { - if element.AcMeasuredPhases == nil || *element.AcMeasuredPhases != phase { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return permitted values for all Electrical Connections -func (e *ElectricalConnection) GetPermittedValueSets() ([]model.ElectricalConnectionPermittedValueSetDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.ElectricalConnectionPermittedValueSetListDataType](e.featureRemote, model.FunctionTypeElectricalConnectionPermittedValueSetListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.ElectricalConnectionPermittedValueSetData, nil -} - -// return permitted valueset for a provided measuremnetId -func (e *ElectricalConnection) GetPermittedValueSetForParameterId(parameterId model.ElectricalConnectionParameterIdType) (*model.ElectricalConnectionPermittedValueSetDataType, error) { - values, err := e.GetPermittedValueSets() - if err != nil { - return nil, err - } - - for _, element := range values { - if element.ParameterId == nil || *element.ParameterId != parameterId { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return permitted valueset for a provided measuremnetId -func (e *ElectricalConnection) GetPermittedValueSetForMeasurementId(measurementId model.MeasurementIdType) (*model.ElectricalConnectionPermittedValueSetDataType, error) { - param, err := e.GetParameterDescriptionForMeasurementId(measurementId) - if err != nil { - return nil, err - } - - values, err := e.GetPermittedValueSets() - if err != nil { - return nil, err - } - - for _, element := range values { - if element.ParameterId == nil || *element.ParameterId != *param.ParameterId { - continue - } - - return &element, nil - } - - return nil, api.ErrDataNotAvailable -} - -// returns minimum, maximum, default/pause limit values -func (e *ElectricalConnection) GetLimitsForParameterId(parameterId model.ElectricalConnectionParameterIdType) (float64, float64, float64, error) { - data, err := e.GetPermittedValueSetForParameterId(parameterId) - if err != nil || data.ElectricalConnectionId == nil || data.PermittedValueSet == nil { - return 0, 0, 0, err - } - - var resultMin, resultMax, resultDefault float64 - - for _, set := range data.PermittedValueSet { - if set.Value != nil && len(set.Value) > 0 { - resultDefault = set.Value[0].GetValue() - } - if set.Range != nil { - for _, rangeItem := range set.Range { - if rangeItem.Min != nil { - resultMin = rangeItem.Min.GetValue() - } - if rangeItem.Max != nil { - resultMax = rangeItem.Max.GetValue() - } - } - } - } - - return resultMin, resultMax, resultDefault, nil -} - -// Adjust a value to be within the permitted value range -func (e *ElectricalConnection) AdjustValueToBeWithinPermittedValuesForParameter(value float64, parameterId model.ElectricalConnectionParameterIdType) float64 { - permittedValues, err := e.GetPermittedValueSetForParameterId(parameterId) - if err != nil { - return value - } - - data := permittedValues.PermittedValueSet - - var defaultValue, minValue, maxValue float64 - var hasDefaultValue, hasRange bool - - for _, element := range data { - // is a value set - if element.Value != nil && len(element.Value) > 0 { - defaultValue = element.Value[0].GetValue() - hasDefaultValue = true - } - // is a range set - if element.Range != nil && len(element.Range) > 0 { - if element.Range[0].Min != nil { - minValue = element.Range[0].Min.GetValue() - } - if element.Range[0].Max != nil { - maxValue = element.Range[0].Max.GetValue() - } - hasRange = true - } - } - - if hasRange { - if hasDefaultValue && value < minValue { - value = defaultValue - } - if value > maxValue { - value = maxValue - } - } - - return value -} - -// return characteristics for a Electrical Connections -func (e *ElectricalConnection) GetCharacteristics() ([]model.ElectricalConnectionCharacteristicDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.ElectricalConnectionCharacteristicListDataType](e.featureRemote, model.FunctionTypeElectricalConnectionCharacteristicListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.ElectricalConnectionCharacteristicData, nil -} - -// return characteristics for a Electrical Connections -func (e *ElectricalConnection) GetCharacteristicForContextType( - context model.ElectricalConnectionCharacteristicContextType, - cType model.ElectricalConnectionCharacteristicTypeType, -) (*model.ElectricalConnectionCharacteristicDataType, error) { - data, err := e.GetCharacteristics() - if err != nil || data == nil || len(data) == 0 { - return nil, api.ErrDataNotAvailable - } - - for _, item := range data { - if item.CharacteristicId != nil && - item.CharacteristicContext != nil && - *item.CharacteristicContext == context && - item.CharacteristicType != nil && - *item.CharacteristicType == cType { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} diff --git a/features/electricalconnection_test.go b/features/electricalconnection_test.go deleted file mode 100644 index e26b9dd6..00000000 --- a/features/electricalconnection_test.go +++ /dev/null @@ -1,582 +0,0 @@ -package features_test - -import ( - "testing" - - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" - shipapi "github.com/enbility/ship-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -func TestElectricalConnectionSuite(t *testing.T) { - suite.Run(t, new(ElectricalConnectionSuite)) -} - -type ElectricalConnectionSuite struct { - suite.Suite - - localEntity spineapi.EntityLocalInterface - remoteEntity spineapi.EntityRemoteInterface - - electricalConnection *features.ElectricalConnection - sentMessage []byte -} - -var _ shipapi.ShipConnectionDataWriterInterface = (*ElectricalConnectionSuite)(nil) - -func (s *ElectricalConnectionSuite) WriteShipMessageWithPayload(message []byte) { - s.sentMessage = message -} - -func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { - s.localEntity, s.remoteEntity = setupFeatures( - s.T(), - s, - []featureFunctions{ - { - featureType: model.FeatureTypeTypeElectricalConnection, - functions: []model.FunctionType{ - model.FunctionTypeElectricalConnectionDescriptionListData, - model.FunctionTypeElectricalConnectionParameterDescriptionListData, - model.FunctionTypeElectricalConnectionPermittedValueSetListData, - model.FunctionTypeElectricalConnectionCharacteristicListData, - }, - }, - }, - ) - - var err error - s.electricalConnection, err = features.NewElectricalConnection(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.electricalConnection) -} - -func (s *ElectricalConnectionSuite) Test_RequestDescriptions() { - counter, err := s.electricalConnection.RequestDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *ElectricalConnectionSuite) Test_RequestParameterDescriptions() { - counter, err := s.electricalConnection.RequestParameterDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *ElectricalConnectionSuite) Test_RequestPermittedValueSets() { - counter, err := s.electricalConnection.RequestPermittedValueSets() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *ElectricalConnectionSuite) Test_RequestCharacteristics() { - counter, err := s.electricalConnection.RequestCharacteristics() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *ElectricalConnectionSuite) Test_GetDescriptions() { - data, err := s.electricalConnection.GetDescriptions() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetDescriptionForMeasurementId() { - measurementId := model.MeasurementIdType(1) - data, err := s.electricalConnection.GetDescriptionForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetDescriptionForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetDescriptionForMeasurementId(measurementId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetParameterDescriptions() { - data, err := s.electricalConnection.GetParameterDescriptions() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetParameterDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForScope() { - data, err := s.electricalConnection.GetParameterDescriptionForScopeType(model.ScopeTypeTypeACPowerTotal) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetParameterDescriptionForScopeType(model.ScopeTypeTypeACPowerTotal) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionPower() - - data, err = s.electricalConnection.GetParameterDescriptionForScopeType(model.ScopeTypeTypeACPowerTotal) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - data, err = s.electricalConnection.GetParameterDescriptionForScopeType(model.ScopeTypeTypeACCurrent) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForParameterId() { - parametertId := model.ElectricalConnectionParameterIdType(1) - data, err := s.electricalConnection.GetParameterDescriptionForParameterId(parametertId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetParameterDescriptionForParameterId(parametertId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetParameterDescriptionForParameterId(parametertId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - parametertId = model.ElectricalConnectionParameterIdType(10) - data, err = s.electricalConnection.GetParameterDescriptionForParameterId(parametertId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForMeasurementId() { - measurementId := model.MeasurementIdType(1) - data, err := s.electricalConnection.GetParameterDescriptionForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetParameterDescriptionForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetParameterDescriptionForMeasurementId(measurementId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - measurementId = model.MeasurementIdType(10) - data, err = s.electricalConnection.GetParameterDescriptionForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForMeasuredPhase() { - phase := model.ElectricalConnectionPhaseNameTypeA - data, err := s.electricalConnection.GetParameterDescriptionForMeasuredPhase(phase) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.electricalConnection.GetParameterDescriptionForMeasuredPhase(phase) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetParameterDescriptionForMeasuredPhase(phase) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - phase = model.ElectricalConnectionPhaseNameTypeBc - data, err = s.electricalConnection.GetParameterDescriptionForMeasuredPhase(phase) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetPermittedValueSets() { - data, err := s.electricalConnection.GetPermittedValueSets() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addPermittedValueSet() - - data, err = s.electricalConnection.GetPermittedValueSets() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - s.addParamDescriptionPower() - - data, err = s.electricalConnection.GetPermittedValueSets() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetsEmptyElli() { - data, err := s.electricalConnection.GetPermittedValueSets() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addPermittedValueSetEmptyElli() - - data, err = s.electricalConnection.GetPermittedValueSets() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetForParameterId() { - parametertId := model.ElectricalConnectionParameterIdType(1) - data, err := s.electricalConnection.GetPermittedValueSetForParameterId(parametertId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addPermittedValueSet() - - data, err = s.electricalConnection.GetPermittedValueSetForParameterId(parametertId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - parametertId = model.ElectricalConnectionParameterIdType(10) - data, err = s.electricalConnection.GetPermittedValueSetForParameterId(parametertId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetForMeasurementId() { - measurementId := model.MeasurementIdType(1) - data, err := s.electricalConnection.GetPermittedValueSetForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addPermittedValueSet() - - data, err = s.electricalConnection.GetPermittedValueSetForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addParamDescriptionCurrents() - - data, err = s.electricalConnection.GetPermittedValueSetForMeasurementId(measurementId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - measurementId = model.MeasurementIdType(10) - data, err = s.electricalConnection.GetPermittedValueSetForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetLimitsForParameterId() { - parameterId := model.ElectricalConnectionParameterIdType(1) - minV, maxV, defaultV, err := s.electricalConnection.GetLimitsForParameterId(parameterId) - assert.NotNil(s.T(), err) - assert.Equal(s.T(), minV, 0.0) - assert.Equal(s.T(), maxV, 0.0) - assert.Equal(s.T(), defaultV, 0.0) - - s.addPermittedValueSet() - s.addParamDescriptionCurrents() - - minV, maxV, defaultV, err = s.electricalConnection.GetLimitsForParameterId(parameterId) - assert.Nil(s.T(), err) - assert.Equal(s.T(), minV, 2.0) - assert.Equal(s.T(), maxV, 16.0) - assert.Equal(s.T(), defaultV, 0.1) -} - -func (s *ElectricalConnectionSuite) Test_AdjustValueToBeWithinPermittedValuesForParameter() { - parameterId := model.ElectricalConnectionParameterIdType(1) - s.addPermittedValueSet() - s.addParamDescriptionCurrents() - - value := s.electricalConnection.AdjustValueToBeWithinPermittedValuesForParameter(20, parameterId) - assert.Equal(s.T(), value, 16.0) - value = s.electricalConnection.AdjustValueToBeWithinPermittedValuesForParameter(2, parameterId) - assert.Equal(s.T(), value, 2.0) - value = s.electricalConnection.AdjustValueToBeWithinPermittedValuesForParameter(1, parameterId) - assert.Equal(s.T(), value, 0.1) -} - -func (s *ElectricalConnectionSuite) Test_GetCharacteristics() { - data, err := s.electricalConnection.GetCharacteristics() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addCharacteristics() - - data, err = s.electricalConnection.GetCharacteristics() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *ElectricalConnectionSuite) Test_GetCharacteristicForContextType() { - data, err := s.electricalConnection.GetCharacteristicForContextType( - model.ElectricalConnectionCharacteristicContextTypeEntity, - model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addCharacteristics() - - data, err = s.electricalConnection.GetCharacteristicForContextType( - model.ElectricalConnectionCharacteristicContextTypeEntity, - model.ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - data, err = s.electricalConnection.GetCharacteristicForContextType( - model.ElectricalConnectionCharacteristicContextTypeEntity, - model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -// helper - -func (s *ElectricalConnectionSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionDescriptionListDataType{ - ElectricalConnectionDescriptionData: []model.ElectricalConnectionDescriptionDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - PowerSupplyType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcConnectedPhases: util.Ptr(uint(3)), - PositiveEnergyDirection: util.Ptr(model.EnergyDirectionTypeConsume), - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionDescriptionListData, fData, nil, nil) -} - -func (s *ElectricalConnectionSuite) addCharacteristics() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionCharacteristicListDataType{ - ElectricalConnectionCharacteristicData: []model.ElectricalConnectionCharacteristicDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), - CharacteristicId: util.Ptr(model.ElectricalConnectionCharacteristicIdType(0)), - CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), - CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax), - Value: model.NewScaledNumberType(98), - Unit: util.Ptr(model.UnitOfMeasurementTypeWh), - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, fData, nil, nil) -} - -func (s *ElectricalConnectionSuite) addParamDescriptionCurrents() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionParameterDescriptionListDataType{ - ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), - MeasurementId: util.Ptr(model.MeasurementIdType(1)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)), - MeasurementId: util.Ptr(model.MeasurementIdType(4)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(3)), - MeasurementId: util.Ptr(model.MeasurementIdType(2)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(4)), - MeasurementId: util.Ptr(model.MeasurementIdType(5)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(5)), - MeasurementId: util.Ptr(model.MeasurementIdType(3)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(6)), - MeasurementId: util.Ptr(model.MeasurementIdType(6)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(7)), - MeasurementId: util.Ptr(model.MeasurementIdType(7)), - VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc), - AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), - AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), - AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) -} - -func (s *ElectricalConnectionSuite) addParamDescriptionPower() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionParameterDescriptionListDataType{ - ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(8)), - AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc), - ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) -} - -func (s *ElectricalConnectionSuite) addPermittedValueSet() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionPermittedValueSetListDataType{ - ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), - PermittedValueSet: []model.ScaledNumberSetType{ - { - Value: []model.ScaledNumberType{ - *model.NewScaledNumberType(0.1), - }, - Range: []model.ScaledNumberRangeType{ - { - Min: model.NewScaledNumberType(2), - Max: model.NewScaledNumberType(16), - }, - }, - }, - }, - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(3)), - PermittedValueSet: []model.ScaledNumberSetType{ - { - Value: []model.ScaledNumberType{ - *model.NewScaledNumberType(0.1), - }, - Range: []model.ScaledNumberRangeType{ - { - Min: model.NewScaledNumberType(2), - Max: model.NewScaledNumberType(16), - }, - }, - }, - }, - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(5)), - PermittedValueSet: []model.ScaledNumberSetType{ - { - Value: []model.ScaledNumberType{ - *model.NewScaledNumberType(0.1), - }, - Range: []model.ScaledNumberRangeType{ - { - Min: model.NewScaledNumberType(2), - Max: model.NewScaledNumberType(16), - }, - }, - }, - }, - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(8)), - PermittedValueSet: []model.ScaledNumberSetType{ - { - Value: []model.ScaledNumberType{ - *model.NewScaledNumberType(0.1), - }, - Range: []model.ScaledNumberRangeType{ - { - Min: model.NewScaledNumberType(400), - Max: model.NewScaledNumberType(113664), - }, - }, - }, - }, - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) -} - -func (s *ElectricalConnectionSuite) addPermittedValueSetEmptyElli() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.ElectricalConnectionPermittedValueSetListDataType{ - ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{ - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), - PermittedValueSet: []model.ScaledNumberSetType{}, - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), - }, - { - ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), - ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)), - }, - }, - } - rF.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) -} diff --git a/features/internal/deviceclassification.go b/features/internal/deviceclassification.go new file mode 100644 index 00000000..b37d8bc6 --- /dev/null +++ b/features/internal/deviceclassification.go @@ -0,0 +1,37 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceClassificationCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalDeviceClassification(featureLocal spineapi.FeatureLocalInterface) *DeviceClassificationCommon { + return &DeviceClassificationCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteDeviceClassification(featureRemote spineapi.FeatureRemoteInterface) *DeviceClassificationCommon { + return &DeviceClassificationCommon{ + featureRemote: featureRemote, + } +} + +var _ api.DeviceClassificationCommonInterface = (*DeviceClassificationCommon)(nil) + +// get the current manufacturer details for a remote device entity +func (d *DeviceClassificationCommon) GetManufacturerDetails() (*model.DeviceClassificationManufacturerDataType, error) { + function := model.FunctionTypeDeviceClassificationManufacturerData + data, err := featureDataCopyOfType[model.DeviceClassificationManufacturerDataType](d.featureLocal, d.featureRemote, function) + if err != nil || data == nil { + return nil, api.ErrDataNotAvailable + } + + return data, nil +} diff --git a/features/deviceclassification_test.go b/features/internal/deviceclassification_test.go similarity index 67% rename from features/deviceclassification_test.go rename to features/internal/deviceclassification_test.go index d6c442ac..ac7ee441 100644 --- a/features/deviceclassification_test.go +++ b/features/internal/deviceclassification_test.go @@ -1,9 +1,9 @@ -package features_test +package internal_test import ( "testing" - "github.com/enbility/eebus-go/features" + "github.com/enbility/eebus-go/features/internal" "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" @@ -22,8 +22,12 @@ type DeviceClassificationSuite struct { localEntity spineapi.EntityLocalInterface remoteEntity spineapi.EntityRemoteInterface - deviceClassification *features.DeviceClassification - sentMessage []byte + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.DeviceClassificationCommon + sentMessage []byte } var _ shipapi.ShipConnectionDataWriterInterface = (*DeviceClassificationSuite)(nil) @@ -46,24 +50,22 @@ func (s *DeviceClassificationSuite) BeforeTest(suiteName, testName string) { }, ) - var err error - s.deviceClassification, err = features.NewDeviceClassification(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.deviceClassification) -} + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceClassification, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalDeviceClassification(s.localFeature) + assert.NotNil(s.T(), s.localSut) -func (s *DeviceClassificationSuite) Test_RequestManufacturerDetails() { - counter, err := s.deviceClassification.RequestManufacturerDetails() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceClassification, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteDeviceClassification(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) } func (s *DeviceClassificationSuite) Test_GetManufacturerDetails() { - result, err := s.deviceClassification.GetManufacturerDetails() + result, err := s.remoteSut.GetManufacturerDetails() assert.NotNil(s.T(), err) assert.Nil(s.T(), result) - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) fData := &model.DeviceClassificationManufacturerDataType{ DeviceName: util.Ptr(model.DeviceClassificationStringType("brand")), DeviceCode: util.Ptr(model.DeviceClassificationStringType("brand")), @@ -78,9 +80,14 @@ func (s *DeviceClassificationSuite) Test_GetManufacturerDetails() { ManufacturerLabel: util.Ptr(model.LabelType("label")), ManufacturerDescription: util.Ptr(model.DescriptionType("description")), } - rF.UpdateData(model.FunctionTypeDeviceClassificationManufacturerData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeDeviceClassificationManufacturerData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeDeviceClassificationManufacturerData, fData, nil, nil) + + result, err = s.remoteSut.GetManufacturerDetails() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) - result, err = s.deviceClassification.GetManufacturerDetails() + result, err = s.localSut.GetManufacturerDetails() assert.Nil(s.T(), err) assert.NotNil(s.T(), result) } diff --git a/features/internal/deviceconfiguration.go b/features/internal/deviceconfiguration.go new file mode 100644 index 00000000..a8ea257d --- /dev/null +++ b/features/internal/deviceconfiguration.go @@ -0,0 +1,130 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceConfigurationCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalDeviceConfiguration(featureLocal spineapi.FeatureLocalInterface) *DeviceConfigurationCommon { + return &DeviceConfigurationCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteDeviceConfiguration(featureRemote spineapi.FeatureRemoteInterface) *DeviceConfigurationCommon { + return &DeviceConfigurationCommon{ + featureRemote: featureRemote, + } +} + +var _ api.DeviceConfigurationCommonInterface = (*DeviceConfigurationCommon)(nil) + +// check if spine.EventPayload Data contains data for a given filter +// +// data type will be checked for model.DeviceConfigurationKeyValueListDataType, +// filter type will be checked for model.DeviceConfigurationKeyValueDescriptionDataType +func (d *DeviceConfigurationCommon) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.DeviceConfigurationKeyValueListDataType) + filterData, ok2 := filter.(model.DeviceConfigurationKeyValueDescriptionDataType) + if !ok || !ok2 { + return false + } + + descs, err := d.GetKeyValueDescriptionsForFilter(filterData) + if err != nil { + return false + } + for _, desc := range descs { + if desc.KeyId == nil { + continue + } + + for _, item := range data.DeviceConfigurationKeyValueData { + if item.KeyId != nil && + *item.KeyId == *desc.KeyId || + item.Value != nil { + return true + } + } + } + + return false +} + +// Get the description for a given keyId +// +// Will return nil if no matching description is found +func (d *DeviceConfigurationCommon) GetKeyValueDescriptionFoKeyId(keyId model.DeviceConfigurationKeyIdType) ( + *model.DeviceConfigurationKeyValueDescriptionDataType, error) { + data, err := d.GetKeyValueDescriptionsForFilter(model.DeviceConfigurationKeyValueDescriptionDataType{KeyId: &keyId}) + + if err != nil || len(data) != 1 { + return nil, api.ErrDataNotAvailable + } + + return &data[0], nil +} + +// Get the description for a given value combination +// +// Returns an error if no matching description is found +func (d *DeviceConfigurationCommon) GetKeyValueDescriptionsForFilter( + filter model.DeviceConfigurationKeyValueDescriptionDataType, +) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) { + function := model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData + + data, err := featureDataCopyOfType[model.DeviceConfigurationKeyValueDescriptionListDataType](d.featureLocal, d.featureRemote, function) + if err != nil || data == nil || data.DeviceConfigurationKeyValueDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.DeviceConfigurationKeyValueDescriptionDataType]( + data.DeviceConfigurationKeyValueDescriptionData, filter) + return result, nil +} + +// Get the key value data for a given keyId +// +// Will return nil if no data is available +func (d *DeviceConfigurationCommon) GetKeyValueDataForKeyId(keyId model.DeviceConfigurationKeyIdType) ( + *model.DeviceConfigurationKeyValueDataType, error) { + return d.GetKeyValueDataForFilter(model.DeviceConfigurationKeyValueDescriptionDataType{KeyId: &keyId}) +} + +// Get key value data for a given filter +// +// Will return nil if no data is available +func (d *DeviceConfigurationCommon) GetKeyValueDataForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) ( + *model.DeviceConfigurationKeyValueDataType, error) { + function := model.FunctionTypeDeviceConfigurationKeyValueListData + + descriptions, err := d.GetKeyValueDescriptionsForFilter(filter) + if err != nil || descriptions == nil || len(descriptions) == 0 { + return nil, api.ErrDataNotAvailable + } + + description := descriptions[0] + + data, err := featureDataCopyOfType[model.DeviceConfigurationKeyValueListDataType](d.featureLocal, d.featureRemote, function) + if err != nil || data == nil || data.DeviceConfigurationKeyValueData == nil { + return nil, api.ErrDataNotAvailable + } + + for _, item := range data.DeviceConfigurationKeyValueData { + if item.KeyId != nil && *item.KeyId == *description.KeyId { + return &item, nil + } + } + + return nil, api.ErrDataNotAvailable +} diff --git a/features/internal/deviceconfiguration_test.go b/features/internal/deviceconfiguration_test.go new file mode 100644 index 00000000..425737a3 --- /dev/null +++ b/features/internal/deviceconfiguration_test.go @@ -0,0 +1,468 @@ +package internal_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestDeviceConfigurationSuite(t *testing.T) { + suite.Run(t, new(DeviceConfigurationSuite)) +} + +type DeviceConfigurationSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.DeviceConfigurationCommon +} + +func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeDeviceConfiguration, + functions: []model.FunctionType{ + model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, + model.FunctionTypeDeviceConfigurationKeyValueListData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalDeviceConfiguration(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteDeviceConfiguration(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *DeviceConfigurationSuite) Test_CheckEventPayloadDataForFilter() { + keyName := model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit + keyName2 := model.DeviceConfigurationKeyNameTypeFailsafeProductionActivePowerLimit + + filter := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: &keyName, + } + exists := s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + exists = s.localSut.CheckEventPayloadDataForFilter(keyName, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(keyName, filter) + assert.False(s.T(), exists) + + descData := &model.DeviceConfigurationKeyValueDescriptionListDataType{ + DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{ + { + KeyName: util.Ptr(keyName), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + KeyName: util.Ptr(keyName2), + }, + }, + } + + fErr := s.remoteFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.localFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + + exists = s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + keyData := &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{}, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(keyData, filter) + assert.False(s.T(), exists) + + descData = &model.DeviceConfigurationKeyValueDescriptionListDataType{ + DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{ + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + KeyName: util.Ptr(keyName), + }, + }, + } + + fErr = s.remoteFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.localFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + + exists = s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + keyData = &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{ + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + Value: &model.DeviceConfigurationKeyValueValueType{ + String: util.Ptr(model.DeviceConfigurationKeyValueStringTypeIEC61851), + }, + }, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(keyData, filter) + assert.True(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(keyData, filter) + assert.True(s.T(), exists) +} + +func (s *DeviceConfigurationSuite) Test_DescriptionForKeyId() { + keyId := model.DeviceConfigurationKeyIdType(0) + desc, err := s.localSut.GetKeyValueDescriptionFoKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionFoKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + + s.addDescription() + + desc, err = s.localSut.GetKeyValueDescriptionFoKeyId(keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionFoKeyId(keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) +} + +func (s *DeviceConfigurationSuite) Test_Description() { + keyId := model.DeviceConfigurationKeyIdType(0) + filter := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyId: util.Ptr(keyId), + } + desc, err := s.localSut.GetKeyValueDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + + s.addDescription() + + desc, err = s.localSut.GetKeyValueDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) +} + +func (s *DeviceConfigurationSuite) Test_GetDescriptionForKeyName() { + keyName := model.DeviceConfigurationKeyNameTypeCommunicationsStandard + filter := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: &keyName, + } + desc, err := s.localSut.GetKeyValueDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), desc) + + s.addDescription() + + desc, err = s.localSut.GetKeyValueDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) + desc, err = s.remoteSut.GetKeyValueDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), desc) +} + +func (s *DeviceConfigurationSuite) Test_GetValueForKey() { + keyName := model.DeviceConfigurationKeyNameTypeCommunicationsStandard + valueType := model.DeviceConfigurationKeyValueTypeTypeString + filter := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: &keyName, + ValueType: &valueType, + } + + value, err := s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + + s.addDescription() + + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + + s.addData() + + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeAzimuth) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDate) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeBatteryType) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDateTime) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeTimeToAcDischargePowerMax) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDuration) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeTypeTime) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeType("invalid")) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + + filter.KeyName = util.Ptr(model.DeviceConfigurationKeyNameType("invalid")) + filter.ValueType = util.Ptr(model.DeviceConfigurationKeyValueTypeType("invalid")) + value, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + value, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) +} + +func (s *DeviceConfigurationSuite) Test_GetData() { + filter := model.DeviceConfigurationKeyValueDescriptionDataType{} + + data, err := s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *DeviceConfigurationSuite) Test_GetDataForKeyId() { + keyId := model.DeviceConfigurationKeyIdType(0) + + data, err := s.localSut.GetKeyValueDataForKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetKeyValueDataForKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForKeyId(keyId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetKeyValueDataForKeyId(keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetKeyValueDataForKeyId(keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +// helper + +func (s *DeviceConfigurationSuite) addDescription() { + fData := &model.DeviceConfigurationKeyValueDescriptionListDataType{ + DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{ + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeCommunicationsStandard), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeString), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeAsymmetricChargingSupported), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeBoolean), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber), + Unit: util.Ptr(model.UnitOfMeasurementTypepct), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(3)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeAzimuth), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDate), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(4)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeBatteryType), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDateTime), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(5)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeTimeToAcDischargePowerMax), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeDuration), + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(6)), + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeIncentivesWaitIncentiveWriteable), + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeTime), + }, + }, + } + s.remoteFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, fData, nil, nil) +} + +func (s *DeviceConfigurationSuite) addData() { + fData := &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{ + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(0)), + Value: &model.DeviceConfigurationKeyValueValueType{ + String: util.Ptr(model.DeviceConfigurationKeyValueStringType("test")), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(1)), + Value: &model.DeviceConfigurationKeyValueValueType{ + Boolean: util.Ptr(true), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(2)), + Value: &model.DeviceConfigurationKeyValueValueType{ + ScaledNumber: model.NewScaledNumberType(50), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(3)), + Value: &model.DeviceConfigurationKeyValueValueType{ + Date: model.NewDateType("01.01.2023"), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(4)), + Value: &model.DeviceConfigurationKeyValueValueType{ + DateTime: model.NewDateTimeTypeFromTime(time.Now()), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(5)), + Value: &model.DeviceConfigurationKeyValueValueType{ + Duration: model.NewDurationType(time.Second * 4), + }, + }, + { + KeyId: util.Ptr(model.DeviceConfigurationKeyIdType(6)), + Value: &model.DeviceConfigurationKeyValueValueType{ + Time: model.NewTimeType("13:05"), + }, + }, + }, + } + s.remoteFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, fData, nil, nil) +} diff --git a/features/internal/devicediagnosis.go b/features/internal/devicediagnosis.go new file mode 100644 index 00000000..533e4300 --- /dev/null +++ b/features/internal/devicediagnosis.go @@ -0,0 +1,59 @@ +package internal + +import ( + "time" + + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceDiagnosisCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalDeviceDiagnosis(featureLocal spineapi.FeatureLocalInterface) *DeviceDiagnosisCommon { + return &DeviceDiagnosisCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteDeviceDiagnosis(featureRemote spineapi.FeatureRemoteInterface) *DeviceDiagnosisCommon { + return &DeviceDiagnosisCommon{ + featureRemote: featureRemote, + } +} + +var _ api.DeviceDiagnosisCommonInterface = (*DeviceDiagnosisCommon)(nil) + +// get the current diagnosis state for an device entity +func (d *DeviceDiagnosisCommon) GetState() (*model.DeviceDiagnosisStateDataType, error) { + function := model.FunctionTypeDeviceDiagnosisStateData + + data, err := featureDataCopyOfType[model.DeviceDiagnosisStateDataType](d.featureLocal, d.featureRemote, function) + if err != nil { + return nil, api.ErrDataNotAvailable + } + + return data, nil +} + +// check if the currently available heartbeat data is within a time duration +func (d *DeviceDiagnosisCommon) IsHeartbeatWithinDuration(duration time.Duration) bool { + function := model.FunctionTypeDeviceDiagnosisHeartbeatData + + data, err := featureDataCopyOfType[model.DeviceDiagnosisHeartbeatDataType](d.featureLocal, d.featureRemote, function) + if err != nil || data == nil || data.Timestamp == nil { + return false + } + + timeValue, err := data.Timestamp.GetTime() + if err != nil { + return false + } + + diff := time.Now().UTC().Add(-1 * duration) + + return diff.Compare(timeValue.Local()) <= 0 +} diff --git a/features/internal/devicediagnosis_test.go b/features/internal/devicediagnosis_test.go new file mode 100644 index 00000000..bedc10ae --- /dev/null +++ b/features/internal/devicediagnosis_test.go @@ -0,0 +1,122 @@ +package internal_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestDeviceDiagnosisSuite(t *testing.T) { + suite.Run(t, new(DeviceDiagnosisSuite)) +} + +type DeviceDiagnosisSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.DeviceDiagnosisCommon +} + +func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeDeviceDiagnosis, + functions: []model.FunctionType{ + model.FunctionTypeDeviceDiagnosisHeartbeatData, + model.FunctionTypeDeviceDiagnosisStateData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalDeviceDiagnosis(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeDeviceDiagnosis, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteDeviceDiagnosis(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *DeviceDiagnosisSuite) Test_GetState() { + result, err := s.localSut.GetState() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + result, err = s.remoteSut.GetState() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + fData := &model.DeviceDiagnosisStateDataType{ + OperatingState: util.Ptr(model.DeviceDiagnosisOperatingStateTypeNormalOperation), + PowerSupplyCondition: util.Ptr(model.PowerSupplyConditionTypeGood), + } + s.localFeature.UpdateData(model.FunctionTypeDeviceDiagnosisStateData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeDeviceDiagnosisStateData, fData, nil, nil) + + result, err = s.localSut.GetState() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + result, err = s.remoteSut.GetState() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) +} + +func (s *DeviceDiagnosisSuite) Test_IsHeartbeatWithinDuration() { + result := s.localSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), true, result) // local server automatically generates a first hearbeat! + result = s.remoteSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), false, result) + + now := time.Now().UTC() + + data := &model.DeviceDiagnosisHeartbeatDataType{ + HeartbeatCounter: util.Ptr(uint64(1)), + HeartbeatTimeout: model.NewDurationType(time.Second * 4), + } + + s.localFeature.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) + + result = s.localSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), false, result) + result = s.remoteSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), false, result) + + data.Timestamp = model.NewAbsoluteOrRelativeTimeTypeFromTime(now) + s.localFeature.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeDeviceDiagnosisHeartbeatData, data, nil, nil) + + result = s.localSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), true, result) + result = s.remoteSut.IsHeartbeatWithinDuration(time.Second * 10) + assert.Equal(s.T(), true, result) + + time.Sleep(time.Second * 2) + + result = s.localSut.IsHeartbeatWithinDuration(time.Second * 1) + assert.Equal(s.T(), false, result) + result = s.remoteSut.IsHeartbeatWithinDuration(time.Second * 1) + assert.Equal(s.T(), false, result) +} diff --git a/features/internal/electricalconnection.go b/features/internal/electricalconnection.go new file mode 100644 index 00000000..6688c918 --- /dev/null +++ b/features/internal/electricalconnection.go @@ -0,0 +1,276 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type ElectricalConnectionCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalElectricalConnection(featureLocal spineapi.FeatureLocalInterface) *ElectricalConnectionCommon { + return &ElectricalConnectionCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteElectricalConnection(featureRemote spineapi.FeatureRemoteInterface) *ElectricalConnectionCommon { + return &ElectricalConnectionCommon{ + featureRemote: featureRemote, + } +} + +var _ api.ElectricalConnectionCommonInterface = (*ElectricalConnectionCommon)(nil) + +// check if spine.EventPayload Data contains data for a given filter +// +// data type will be checked for model.ElectricalConnectionPermittedValueSetListDataType, +// filter type will be checked for model.ElectricalConnectionParameterDescriptionDataType +func (e *ElectricalConnectionCommon) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.ElectricalConnectionPermittedValueSetListDataType) + filterData, ok2 := filter.(model.ElectricalConnectionParameterDescriptionDataType) + if !ok || !ok2 { + return false + } + + descs, err := e.GetParameterDescriptionsForFilter(filterData) + if err != nil { + return false + } + for _, desc := range descs { + if desc.ParameterId == nil { + continue + } + + for _, item := range data.ElectricalConnectionPermittedValueSetData { + if item.ParameterId != nil && + *item.ParameterId == *desc.ParameterId && + len(item.PermittedValueSet) != 0 { + return true + } + } + } + + return false +} + +// Get the description for a given filter +// +// Returns an error if no matching description is found +func (e *ElectricalConnectionCommon) GetDescriptionsForFilter( + filter model.ElectricalConnectionDescriptionDataType, +) ([]model.ElectricalConnectionDescriptionDataType, error) { + function := model.FunctionTypeElectricalConnectionDescriptionListData + + data, err := featureDataCopyOfType[model.ElectricalConnectionDescriptionListDataType](e.featureLocal, e.featureRemote, function) + if err != nil || data == nil || data.ElectricalConnectionDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.ElectricalConnectionDescriptionDataType]( + data.ElectricalConnectionDescriptionData, filter) + return result, nil +} + +// return current electrical description for a given parameter description +func (e *ElectricalConnectionCommon) GetDescriptionForParameterDescriptionFilter( + filter model.ElectricalConnectionParameterDescriptionDataType) ( + *model.ElectricalConnectionDescriptionDataType, error) { + param, err := e.GetParameterDescriptionsForFilter(filter) + if err != nil || len(param) == 0 { + return nil, err + } + + descriptions, err := e.GetDescriptionsForFilter(model.ElectricalConnectionDescriptionDataType{}) + if err != nil { + return nil, err + } + + for _, item := range descriptions { + if item.ElectricalConnectionId == nil || + param[0].ElectricalConnectionId == nil || + *item.ElectricalConnectionId != *param[0].ElectricalConnectionId { + continue + } + + return &item, nil + } + + return nil, api.ErrMetadataNotAvailable +} + +// Get the description for a given filter +// +// Returns an error if no matching description is found +func (e *ElectricalConnectionCommon) GetParameterDescriptionsForFilter( + filter model.ElectricalConnectionParameterDescriptionDataType, +) ([]model.ElectricalConnectionParameterDescriptionDataType, error) { + function := model.FunctionTypeElectricalConnectionParameterDescriptionListData + + data, err := featureDataCopyOfType[model.ElectricalConnectionParameterDescriptionListDataType](e.featureLocal, e.featureRemote, function) + if err != nil || data == nil || data.ElectricalConnectionParameterDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.ElectricalConnectionParameterDescriptionDataType]( + data.ElectricalConnectionParameterDescriptionData, filter) + return result, nil +} + +// return permitted values for all Electrical Connections +func (e *ElectricalConnectionCommon) GetPermittedValueSetForFilter( + filter model.ElectricalConnectionPermittedValueSetDataType) ( + []model.ElectricalConnectionPermittedValueSetDataType, error) { + function := model.FunctionTypeElectricalConnectionPermittedValueSetListData + + data, err := featureDataCopyOfType[model.ElectricalConnectionPermittedValueSetListDataType](e.featureLocal, e.featureRemote, function) + if err != nil || data == nil || data.ElectricalConnectionPermittedValueSetData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.ElectricalConnectionPermittedValueSetDataType](data.ElectricalConnectionPermittedValueSetData, filter) + return result, nil +} + +// returns minimum, maximum, default/pause limit values +func (e *ElectricalConnectionCommon) GetPermittedValueDataForFilter( + filter model.ElectricalConnectionPermittedValueSetDataType) ( + float64, float64, float64, error) { + data, err := e.GetPermittedValueSetForFilter(filter) + if err != nil || len(data) != 1 || + data[0].ElectricalConnectionId == nil || + data[0].PermittedValueSet == nil { + return 0, 0, 0, api.ErrDataNotAvailable + } + + var resultMin, resultMax, resultDefault float64 + + for _, set := range data[0].PermittedValueSet { + if set.Value != nil && len(set.Value) > 0 { + resultDefault = set.Value[0].GetValue() + } + if set.Range != nil { + for _, rangeItem := range set.Range { + if rangeItem.Min != nil { + resultMin = rangeItem.Min.GetValue() + } + if rangeItem.Max != nil { + resultMax = rangeItem.Max.GetValue() + } + } + } + } + + return resultMin, resultMax, resultDefault, nil +} + +var PhaseNameMapping = []model.ElectricalConnectionPhaseNameType{ + model.ElectricalConnectionPhaseNameTypeA, + model.ElectricalConnectionPhaseNameTypeB, + model.ElectricalConnectionPhaseNameTypeC} + +// Get the min, max, default current limits for each phase +func (e *ElectricalConnectionCommon) GetPhaseCurrentLimits() ( + resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error) { + for _, phaseName := range PhaseNameMapping { + // electricalParameterDescription contains the measured phase for each measurementId + filter := model.ElectricalConnectionParameterDescriptionDataType{ + AcMeasuredPhases: util.Ptr(phaseName), + } + elParamDesc, err := e.GetParameterDescriptionsForFilter(filter) + if err != nil || len(elParamDesc) != 1 || elParamDesc[0].ParameterId == nil { + continue + } + + filter1 := model.ElectricalConnectionPermittedValueSetDataType{ + ParameterId: elParamDesc[0].ParameterId, + } + dataMin, dataMax, dataDefault, err := e.GetPermittedValueDataForFilter(filter1) + if err != nil { + continue + } + + // Min current data should be derived from min power data + // but as this value is only properly provided via VAS the + // currrent min values can not be trusted. + + resultMin = append(resultMin, dataMin) + resultMax = append(resultMax, dataMax) + resultDefault = append(resultDefault, dataDefault) + } + + if len(resultMin) == 0 { + return nil, nil, nil, api.ErrDataNotAvailable + } + + return resultMin, resultMax, resultDefault, nil +} + +// Adjust a value to be within the permitted value range +func (e *ElectricalConnectionCommon) AdjustValueToBeWithinPermittedValuesForParameterId( + value float64, parameterId model.ElectricalConnectionParameterIdType) float64 { + filter := model.ElectricalConnectionPermittedValueSetDataType{ + ParameterId: ¶meterId, + } + data, err := e.GetPermittedValueSetForFilter(filter) + if err != nil || len(data) != 1 { + return value + } + + var defaultValue, minValue, maxValue float64 + var hasDefaultValue, hasRange bool + + for _, element := range data[0].PermittedValueSet { + // is a value set + if element.Value != nil && len(element.Value) > 0 { + defaultValue = element.Value[0].GetValue() + hasDefaultValue = true + } + // is a range set + if element.Range != nil && len(element.Range) > 0 { + if element.Range[0].Min != nil { + minValue = element.Range[0].Min.GetValue() + } + if element.Range[0].Max != nil { + maxValue = element.Range[0].Max.GetValue() + } + hasRange = true + } + } + + if hasRange { + if hasDefaultValue && value < minValue { + value = defaultValue + } + if value > maxValue { + value = maxValue + } + } + + return value +} + +// Get the characteristics for a given filter +// +// Returns an error if no matching description is found +func (e *ElectricalConnectionCommon) GetCharacteristicsForFilter( + filter model.ElectricalConnectionCharacteristicDataType, +) ([]model.ElectricalConnectionCharacteristicDataType, error) { + function := model.FunctionTypeElectricalConnectionCharacteristicListData + + data, err := featureDataCopyOfType[model.ElectricalConnectionCharacteristicListDataType](e.featureLocal, e.featureRemote, function) + if err != nil || data == nil || data.ElectricalConnectionCharacteristicData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.ElectricalConnectionCharacteristicDataType](data.ElectricalConnectionCharacteristicData, filter) + return result, nil +} diff --git a/features/internal/electricalconnection_test.go b/features/internal/electricalconnection_test.go new file mode 100644 index 00000000..75e81ae2 --- /dev/null +++ b/features/internal/electricalconnection_test.go @@ -0,0 +1,1031 @@ +package internal_test + +import ( + "testing" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestElectricalConnectionSuite(t *testing.T) { + suite.Run(t, new(ElectricalConnectionSuite)) +} + +type ElectricalConnectionSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.ElectricalConnectionCommon +} + +func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeElectricalConnection, + functions: []model.FunctionType{ + model.FunctionTypeElectricalConnectionDescriptionListData, + model.FunctionTypeElectricalConnectionParameterDescriptionListData, + model.FunctionTypeElectricalConnectionPermittedValueSetListData, + model.FunctionTypeElectricalConnectionCharacteristicListData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalElectricalConnection(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteElectricalConnection(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *ElectricalConnectionSuite) Test_CheckEventPayloadDataForFilter() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + } + exists := s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + exists = s.localSut.CheckEventPayloadDataForFilter(filter, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(filter, filter) + assert.False(s.T(), exists) + + descData := &model.ElectricalConnectionParameterDescriptionListDataType{ + ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), + }, + }, + } + + fErr := s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + + exists = s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + permittedData := &model.ElectricalConnectionPermittedValueSetListDataType{ + ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{}, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(permittedData, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(permittedData, filter) + assert.False(s.T(), exists) + + permittedData = &model.ElectricalConnectionPermittedValueSetListDataType{ + ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + PermittedValueSet: []model.ScaledNumberSetType{ + { + Value: []model.ScaledNumberType{*model.NewScaledNumberType(0)}, + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(6), + Max: model.NewScaledNumberType(16), + }, + }, + }, + }, + }, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(permittedData, filter) + assert.True(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(permittedData, filter) + assert.True(s.T(), exists) +} + +func (s *ElectricalConnectionSuite) Test_GetDescriptions() { + filter := model.ElectricalConnectionDescriptionDataType{} + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetDescriptionForMeasurementId() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + } + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetDescriptionForParameterDescriptionFilter() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + } + data, err := s.localSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionForParameterDescriptionFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetParameterDescriptions() { + filter := model.ElectricalConnectionParameterDescriptionDataType{} + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForScope() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionPower() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.ScopeType = util.Ptr(model.ScopeTypeTypeACCurrent) + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + filter.ScopeType = util.Ptr(model.ScopeTypeTypeACCurrent) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForParameterId() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + } + + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.ParameterId = util.Ptr(model.ElectricalConnectionParameterIdType(10)) + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForMeasurementId() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + } + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.MeasurementId = util.Ptr(model.MeasurementIdType(10)) + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetParameterDescriptionForMeasuredPhase() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), + } + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.AcMeasuredPhases = util.Ptr(model.ElectricalConnectionPhaseNameTypeBc) + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetPermittedValueSets() { + filter := model.ElectricalConnectionPermittedValueSetDataType{} + data, err := s.localSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addPermittedValueSet() + + data, err = s.localSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + s.addParamDescriptionPower() + + data, err = s.localSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetsEmptyElli() { + filter := model.ElectricalConnectionPermittedValueSetDataType{} + data, err := s.localSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addPermittedValueSetEmptyElli() + + data, err = s.localSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetForParameterId() { + filter := model.ElectricalConnectionPermittedValueSetDataType{ + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + } + + data, err := s.localSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addPermittedValueSet() + + data, err = s.localSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.ParameterId = util.Ptr(model.ElectricalConnectionParameterIdType(10)) + data, err = s.localSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetPermittedValueSetForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetPermittedValueSetForMeasurementId() { + filter := model.ElectricalConnectionParameterDescriptionDataType{ + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + } + data, err := s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addPermittedValueSet() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addParamDescriptionCurrents() + + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.MeasurementId = util.Ptr(model.MeasurementIdType(10)) + data, err = s.localSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetLimitsForParameterId() { + filter := model.ElectricalConnectionPermittedValueSetDataType{ + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + } + minV, maxV, defaultV, err := s.localSut.GetPermittedValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), minV, 0.0) + assert.Equal(s.T(), maxV, 0.0) + assert.Equal(s.T(), defaultV, 0.0) + minV, maxV, defaultV, err = s.remoteSut.GetPermittedValueDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), minV, 0.0) + assert.Equal(s.T(), maxV, 0.0) + assert.Equal(s.T(), defaultV, 0.0) + + s.addPermittedValueSet() + s.addParamDescriptionCurrents() + + minV, maxV, defaultV, err = s.localSut.GetPermittedValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), minV, 2.0) + assert.Equal(s.T(), maxV, 16.0) + assert.Equal(s.T(), defaultV, 0.1) + minV, maxV, defaultV, err = s.remoteSut.GetPermittedValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), minV, 2.0) + assert.Equal(s.T(), maxV, 16.0) + assert.Equal(s.T(), defaultV, 0.1) +} + +func (s *ElectricalConnectionSuite) Test_AdjustValueToBeWithinPermittedValuesForParameter() { + parameterId := model.ElectricalConnectionParameterIdType(1) + s.addPermittedValueSet() + s.addParamDescriptionCurrents() + + value := s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId) + assert.Equal(s.T(), value, 16.0) + value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(20, parameterId) + assert.Equal(s.T(), value, 16.0) + + value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId) + assert.Equal(s.T(), value, 2.0) + value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(2, parameterId) + assert.Equal(s.T(), value, 2.0) + + value = s.localSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId) + assert.Equal(s.T(), value, 0.1) + value = s.remoteSut.AdjustValueToBeWithinPermittedValuesForParameterId(1, parameterId) + assert.Equal(s.T(), value, 0.1) +} + +func (s *ElectricalConnectionSuite) Test_GetCharacteristics() { + filter := model.ElectricalConnectionCharacteristicDataType{} + data, err := s.localSut.GetCharacteristicsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetCharacteristicsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addCharacteristics() + + data, err = s.localSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetCharacteristicForContextType() { + filter := model.ElectricalConnectionCharacteristicDataType{ + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax), + } + + data, err := s.localSut.GetCharacteristicsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetCharacteristicsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addCharacteristics() + + filter.CharacteristicType = util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax) + data, err = s.localSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + + filter.CharacteristicType = util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax) + data, err = s.localSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_EVCurrentLimits() { + minData, maxData, defaultData, err := s.localSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + + minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + + minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + + paramData := &model.ElectricalConnectionParameterDescriptionListDataType{ + ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)), + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC), + }, + }, + } + + fErr := s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, paramData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, paramData, nil, nil) + assert.Nil(s.T(), fErr) + + minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + + minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), minData) + assert.Nil(s.T(), maxData) + assert.Nil(s.T(), defaultData) + + type permittedStruct struct { + defaultExists bool + defaultValue, expectedDefaultValue float64 + minValue, expectedMinValue float64 + maxValue, expectedMaxValue float64 + } + + tests := []struct { + name string + permitted []permittedStruct + }{ + { + "1 Phase ISO15118", + []permittedStruct{ + {true, 0.1, 0.1, 2, 2, 16, 16}, + }, + }, + { + "1 Phase IEC61851", + []permittedStruct{ + {true, 0.0, 0.0, 6, 6, 16, 16}, + }, + }, + { + "1 Phase IEC61851 Elli", + []permittedStruct{ + {false, 0.0, 0.0, 6, 6, 16, 16}, + }, + }, + { + "3 Phase ISO15118", + []permittedStruct{ + {true, 0.1, 0.1, 2, 2, 16, 16}, + {true, 0.1, 0.1, 2, 2, 16, 16}, + {true, 0.1, 0.1, 2, 2, 16, 16}, + }, + }, + { + "3 Phase IEC61851", + []permittedStruct{ + {true, 0.0, 0.0, 6, 6, 16, 16}, + {true, 0.0, 0.0, 6, 6, 16, 16}, + {true, 0.0, 0.0, 6, 6, 16, 16}, + }, + }, + { + "3 Phase IEC61851 Elli", + []permittedStruct{ + {false, 0.0, 0.0, 6, 6, 16, 16}, + {false, 0.0, 0.0, 6, 6, 16, 16}, + {false, 0.0, 0.0, 6, 6, 16, 16}, + }, + }, + } + + for _, tc := range tests { + s.T().Run(tc.name, func(t *testing.T) { + dataSet := []model.ElectricalConnectionPermittedValueSetDataType{} + permittedData := []model.ScaledNumberSetType{} + for index, data := range tc.permitted { + item := model.ScaledNumberSetType{ + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(data.minValue), + Max: model.NewScaledNumberType(data.maxValue), + }, + }, + } + if data.defaultExists { + item.Value = []model.ScaledNumberType{*model.NewScaledNumberType(data.defaultValue)} + } + permittedData = append(permittedData, item) + + permittedItem := model.ElectricalConnectionPermittedValueSetDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(index)), + PermittedValueSet: permittedData, + } + dataSet = append(dataSet, permittedItem) + } + + permData := &model.ElectricalConnectionPermittedValueSetListDataType{ + ElectricalConnectionPermittedValueSetData: dataSet, + } + + fErr := s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, permData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, permData, nil, nil) + assert.Nil(s.T(), fErr) + + minData, maxData, defaultData, err = s.localSut.GetPhaseCurrentLimits() + assert.Nil(s.T(), err) + + assert.Equal(s.T(), len(tc.permitted), len(minData)) + assert.Equal(s.T(), len(tc.permitted), len(maxData)) + assert.Equal(s.T(), len(tc.permitted), len(defaultData)) + for index, item := range tc.permitted { + assert.Equal(s.T(), item.expectedMinValue, minData[index]) + assert.Equal(s.T(), item.expectedMaxValue, maxData[index]) + assert.Equal(s.T(), item.expectedDefaultValue, defaultData[index]) + } + + minData, maxData, defaultData, err = s.remoteSut.GetPhaseCurrentLimits() + assert.Nil(s.T(), err) + + assert.Equal(s.T(), len(tc.permitted), len(minData)) + assert.Equal(s.T(), len(tc.permitted), len(maxData)) + assert.Equal(s.T(), len(tc.permitted), len(defaultData)) + for index, item := range tc.permitted { + assert.Equal(s.T(), item.expectedMinValue, minData[index]) + assert.Equal(s.T(), item.expectedMaxValue, maxData[index]) + assert.Equal(s.T(), item.expectedDefaultValue, defaultData[index]) + } + }) + } +} + +// helper + +func (s *ElectricalConnectionSuite) addDescription() { + fData := &model.ElectricalConnectionDescriptionListDataType{ + ElectricalConnectionDescriptionData: []model.ElectricalConnectionDescriptionDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + PowerSupplyType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcConnectedPhases: util.Ptr(uint(3)), + PositiveEnergyDirection: util.Ptr(model.EnergyDirectionTypeConsume), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionDescriptionListData, fData, nil, nil) +} + +func (s *ElectricalConnectionSuite) addCharacteristics() { + fData := &model.ElectricalConnectionCharacteristicListDataType{ + ElectricalConnectionCharacteristicData: []model.ElectricalConnectionCharacteristicDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicId: util.Ptr(model.ElectricalConnectionCharacteristicIdType(0)), + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeEnergyCapacityNominalMax), + Value: model.NewScaledNumberType(98), + Unit: util.Ptr(model.UnitOfMeasurementTypeWh), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, fData, nil, nil) +} + +func (s *ElectricalConnectionSuite) addParamDescriptionCurrents() { + fData := &model.ElectricalConnectionParameterDescriptionListDataType{ + ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)), + MeasurementId: util.Ptr(model.MeasurementIdType(4)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeA), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(3)), + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(4)), + MeasurementId: util.Ptr(model.MeasurementIdType(5)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeB), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(5)), + MeasurementId: util.Ptr(model.MeasurementIdType(3)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(6)), + MeasurementId: util.Ptr(model.MeasurementIdType(6)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeC), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(7)), + MeasurementId: util.Ptr(model.MeasurementIdType(7)), + VoltageType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc), + AcMeasuredInReferenceTo: util.Ptr(model.ElectricalConnectionPhaseNameTypeNeutral), + AcMeasurementType: util.Ptr(model.ElectricalConnectionAcMeasurementTypeTypeReal), + AcMeasurementVariant: util.Ptr(model.ElectricalConnectionMeasurandVariantTypeRms), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) +} + +func (s *ElectricalConnectionSuite) addParamDescriptionPower() { + fData := &model.ElectricalConnectionParameterDescriptionListDataType{ + ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(8)), + AcMeasuredPhases: util.Ptr(model.ElectricalConnectionPhaseNameTypeAbc), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, fData, nil, nil) +} + +func (s *ElectricalConnectionSuite) addPermittedValueSet() { + fData := &model.ElectricalConnectionPermittedValueSetListDataType{ + ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + PermittedValueSet: []model.ScaledNumberSetType{ + { + Value: []model.ScaledNumberType{ + *model.NewScaledNumberType(0.1), + }, + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(2), + Max: model.NewScaledNumberType(16), + }, + }, + }, + }, + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(3)), + PermittedValueSet: []model.ScaledNumberSetType{ + { + Value: []model.ScaledNumberType{ + *model.NewScaledNumberType(0.1), + }, + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(2), + Max: model.NewScaledNumberType(16), + }, + }, + }, + }, + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(5)), + PermittedValueSet: []model.ScaledNumberSetType{ + { + Value: []model.ScaledNumberType{ + *model.NewScaledNumberType(0.1), + }, + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(2), + Max: model.NewScaledNumberType(16), + }, + }, + }, + }, + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(8)), + PermittedValueSet: []model.ScaledNumberSetType{ + { + Value: []model.ScaledNumberType{ + *model.NewScaledNumberType(0.1), + }, + Range: []model.ScaledNumberRangeType{ + { + Min: model.NewScaledNumberType(400), + Max: model.NewScaledNumberType(113664), + }, + }, + }, + }, + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) +} + +func (s *ElectricalConnectionSuite) addPermittedValueSetEmptyElli() { + fData := &model.ElectricalConnectionPermittedValueSetListDataType{ + ElectricalConnectionPermittedValueSetData: []model.ElectricalConnectionPermittedValueSetDataType{ + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + PermittedValueSet: []model.ScaledNumberSetType{}, + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(1)), + }, + { + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(2)), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeElectricalConnectionPermittedValueSetListData, fData, nil, nil) +} diff --git a/features/internal/helper.go b/features/internal/helper.go new file mode 100644 index 00000000..e3c1a0a7 --- /dev/null +++ b/features/internal/helper.go @@ -0,0 +1,60 @@ +package internal + +import ( + "reflect" + + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/spine" +) + +func featureDataCopyOfType[T any]( + featureLocal spineapi.FeatureLocalInterface, + featureRemote spineapi.FeatureRemoteInterface, + function model.FunctionType) (*T, error) { + var data *T + var err error + + if featureLocal != nil { + data, err = spine.LocalFeatureDataCopyOfType[*T](featureLocal, function) + } else { + data, err = spine.RemoteFeatureDataCopyOfType[*T](featureRemote, function) + } + + return data, err +} + +func searchFilterInItem[T any](item T, filter T) bool { + v := reflect.ValueOf(item) + + match := true + for i := 0; i < v.NumField(); i++ { + filterField := reflect.ValueOf(filter).Field(i) + itemField := v.Field(i) + + if filterField.Kind() != reflect.Ptr || itemField.Kind() != reflect.Ptr { + continue + } + + if !filterField.IsNil() && !itemField.IsNil() && filterField.Elem().Interface() != itemField.Elem().Interface() { + match = false + break + } + } + + return match +} + +func searchFilterInList[T any](list []T, filter T) []T { + var result []T + + for _, item := range list { + match := searchFilterInItem[T](item, filter) + + if match { + result = append(result, item) + } + } + + return result +} diff --git a/features/internal/helper_test.go b/features/internal/helper_test.go new file mode 100644 index 00000000..d84b0653 --- /dev/null +++ b/features/internal/helper_test.go @@ -0,0 +1,184 @@ +package internal_test + +import ( + "encoding/json" + "sync" + "time" + + "github.com/enbility/eebus-go/util" + shipapi "github.com/enbility/ship-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/spine" + "github.com/stretchr/testify/assert" +) + +type featureFunctions struct { + featureType model.FeatureTypeType + functions []model.FunctionType +} + +type WriteMessageHandler struct { + sentMessages [][]byte + + mux sync.Mutex +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*WriteMessageHandler)(nil) + +func (t *WriteMessageHandler) WriteShipMessageWithPayload(message []byte) { + t.mux.Lock() + defer t.mux.Unlock() + + t.sentMessages = append(t.sentMessages, message) +} + +func (t *WriteMessageHandler) LastMessage() []byte { + t.mux.Lock() + defer t.mux.Unlock() + + if len(t.sentMessages) == 0 { + return nil + } + + return t.sentMessages[len(t.sentMessages)-1] +} + +func (t *WriteMessageHandler) MessageWithReference(msgCounterReference *model.MsgCounterType) []byte { + t.mux.Lock() + defer t.mux.Unlock() + + var datagram model.Datagram + + for _, msg := range t.sentMessages { + if err := json.Unmarshal(msg, &datagram); err != nil { + return nil + } + if datagram.Datagram.Header.MsgCounterReference == nil { + continue + } + if uint(*datagram.Datagram.Header.MsgCounterReference) != uint(*msgCounterReference) { + continue + } + if datagram.Datagram.Payload.Cmd[0].ResultData != nil { + continue + } + + return msg + } + + return nil +} + +func (t *WriteMessageHandler) ResultWithReference(msgCounterReference *model.MsgCounterType) []byte { + t.mux.Lock() + defer t.mux.Unlock() + + var datagram model.Datagram + + for _, msg := range t.sentMessages { + if err := json.Unmarshal(msg, &datagram); err != nil { + return nil + } + if datagram.Datagram.Header.MsgCounterReference == nil { + continue + } + if uint(*datagram.Datagram.Header.MsgCounterReference) != uint(*msgCounterReference) { + continue + } + if datagram.Datagram.Payload.Cmd[0].ResultData == nil { + continue + } + + return msg + } + + return nil +} + +func setupFeatures( + t assert.TestingT, + dataCon shipapi.ShipConnectionDataWriterInterface, + featureFunctions []featureFunctions, +) (spineapi.EntityLocalInterface, spineapi.EntityRemoteInterface) { + localDevice := spine.NewDeviceLocal("TestBrandName", "TestDeviceModel", "TestSerialNumber", "TestDeviceCode", + "TestDeviceAddress", model.DeviceTypeTypeEnergyManagementSystem, model.NetworkManagementFeatureSetTypeSmart, time.Second*4) + localEntity := spine.NewEntityLocal(localDevice, model.EntityTypeTypeCEM, spine.NewAddressEntityType([]uint{1})) + + for i, item := range featureFunctions { + f := spine.NewFeatureLocal(uint(i+1), localEntity, item.featureType, model.RoleTypeClient) + localEntity.AddFeature(f) + + f = spine.NewFeatureLocal(uint(i+1), localEntity, item.featureType, model.RoleTypeServer) + for _, function := range item.functions { + f.AddFunctionType(function, true, true) + } + localEntity.AddFeature(f) + } + + localDevice.AddEntity(localEntity) + + remoteDeviceName := "remoteDevice" + sender := spine.NewSender(dataCon) + remoteDevice := spine.NewDeviceRemote(localDevice, "test", sender) + data := &model.NodeManagementDetailedDiscoveryDataType{ + DeviceInformation: &model.NodeManagementDetailedDiscoveryDeviceInformationType{ + Description: &model.NetworkManagementDeviceDescriptionDataType{ + DeviceAddress: &model.DeviceAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + }, + }, + }, + EntityInformation: []model.NodeManagementDetailedDiscoveryEntityInformationType{ + { + Description: &model.NetworkManagementEntityDescriptionDataType{ + EntityAddress: &model.EntityAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + Entity: []model.AddressEntityType{1}, + }, + EntityType: util.Ptr(model.EntityTypeTypeEVSE), + }, + }, + }, + } + + var features []model.NodeManagementDetailedDiscoveryFeatureInformationType + for i, item := range featureFunctions { + featureI := model.NodeManagementDetailedDiscoveryFeatureInformationType{ + Description: &model.NetworkManagementFeatureDescriptionDataType{ + FeatureAddress: &model.FeatureAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + Entity: []model.AddressEntityType{1}, + Feature: util.Ptr(model.AddressFeatureType(i + 1)), + }, + FeatureType: util.Ptr(item.featureType), + Role: util.Ptr(model.RoleTypeServer), + }, + } + var supportedFcts []model.FunctionPropertyType + for _, function := range item.functions { + supportedFct := model.FunctionPropertyType{ + Function: util.Ptr(function), + PossibleOperations: &model.PossibleOperationsType{ + Read: &model.PossibleOperationsReadType{}, + Write: &model.PossibleOperationsWriteType{}, + }, + } + + supportedFcts = append(supportedFcts, supportedFct) + } + featureI.Description.SupportedFunction = supportedFcts + features = append(features, featureI) + } + data.FeatureInformation = features + + remoteEntities, err := remoteDevice.AddEntityAndFeatures(true, data) + assert.Nil(t, err) + assert.NotNil(t, remoteEntities) + assert.NotEqual(t, 0, len(remoteEntities)) + remoteDevice.UpdateDevice(data.DeviceInformation.Description) + + localDevice.AddRemoteDeviceForSki("test", remoteDevice) + + return localEntity, remoteEntities[0] +} diff --git a/features/internal/identification.go b/features/internal/identification.go new file mode 100644 index 00000000..26575513 --- /dev/null +++ b/features/internal/identification.go @@ -0,0 +1,63 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type IdentificationCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalIdentification(featureLocal spineapi.FeatureLocalInterface) *IdentificationCommon { + return &IdentificationCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteIdentification(featureRemote spineapi.FeatureRemoteInterface) *IdentificationCommon { + return &IdentificationCommon{ + featureRemote: featureRemote, + } +} + +var _ api.IdentificationCommonInterface = (*IdentificationCommon)(nil) + +// check if spine.EventPayload Data contains identification data +// +// data type will be checked for model.IdentificationListDataType +func (i *IdentificationCommon) CheckEventPayloadDataForFilter(payloadData any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.IdentificationListDataType) + if !ok { + return false + } + + for _, item := range data.IdentificationData { + if item.IdentificationId == nil || item.IdentificationValue == nil { + continue + } + + return true + } + + return false +} + +// return current values for Identification +func (i *IdentificationCommon) GetDataForFilter(filter model.IdentificationDataType) ([]model.IdentificationDataType, error) { + function := model.FunctionTypeIdentificationListData + + data, err := featureDataCopyOfType[model.IdentificationListDataType](i.featureLocal, i.featureRemote, function) + if err != nil || data == nil || data.IdentificationData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.IdentificationDataType](data.IdentificationData, filter) + return result, nil +} diff --git a/features/internal/identification_test.go b/features/internal/identification_test.go new file mode 100644 index 00000000..85a18159 --- /dev/null +++ b/features/internal/identification_test.go @@ -0,0 +1,134 @@ +package internal_test + +import ( + "testing" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestIdentificationSuite(t *testing.T) { + suite.Run(t, new(IdentificationSuite)) +} + +type IdentificationSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.IdentificationCommon +} + +func (s *IdentificationSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeIdentification, + functions: []model.FunctionType{ + model.FunctionTypeIdentificationListData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeIdentification, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalIdentification(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeIdentification, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteIdentification(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *IdentificationSuite) Test_CheckEventPayloadDataForFilter() { + exists := s.localSut.CheckEventPayloadDataForFilter(nil) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil) + assert.False(s.T(), exists) + + temp := true + exists = s.localSut.CheckEventPayloadDataForFilter(temp) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(temp) + assert.False(s.T(), exists) + + data := &model.IdentificationListDataType{ + IdentificationData: []model.IdentificationDataType{}, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(data) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(data) + assert.False(s.T(), exists) + + data = &model.IdentificationListDataType{ + IdentificationData: []model.IdentificationDataType{ + { + IdentificationId: util.Ptr(model.IdentificationIdType(0)), + }, + { + IdentificationId: util.Ptr(model.IdentificationIdType(1)), + IdentificationType: util.Ptr(model.IdentificationTypeTypeEui64), + IdentificationValue: util.Ptr(model.IdentificationValueType("test")), + }, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(data) + assert.True(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(data) + assert.True(s.T(), exists) +} + +func (s *IdentificationSuite) Test_GetValues() { + filter := model.IdentificationDataType{} + data, err := s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +// helper + +func (s *IdentificationSuite) addData() { + fData := &model.IdentificationListDataType{ + IdentificationData: []model.IdentificationDataType{ + { + IdentificationId: util.Ptr(model.IdentificationIdType(0)), + IdentificationType: util.Ptr(model.IdentificationTypeTypeEui64), + IdentificationValue: util.Ptr(model.IdentificationValueType("test")), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeIdentificationListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeIdentificationListData, fData, nil, nil) +} diff --git a/features/internal/incentivetable.go b/features/internal/incentivetable.go new file mode 100644 index 00000000..a5588fd5 --- /dev/null +++ b/features/internal/incentivetable.go @@ -0,0 +1,71 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type IncentiveTableCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalIncentiveTable(featureLocal spineapi.FeatureLocalInterface) *IncentiveTableCommon { + return &IncentiveTableCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteIncentiveTable(featureRemote spineapi.FeatureRemoteInterface) *IncentiveTableCommon { + return &IncentiveTableCommon{ + featureRemote: featureRemote, + } +} + +var _ api.IncentiveTableCommonInterface = (*IncentiveTableCommon)(nil) + +// return list of descriptions for a given filter +func (i *IncentiveTableCommon) GetDescriptionsForFilter( + filter model.TariffDescriptionDataType, +) ([]model.IncentiveTableDescriptionType, error) { + function := model.FunctionTypeIncentiveTableDescriptionData + data, err := featureDataCopyOfType[model.IncentiveTableDescriptionDataType](i.featureLocal, i.featureRemote, function) + if err != nil || data == nil || data.IncentiveTableDescription == nil { + return nil, api.ErrDataNotAvailable + } + + var result []model.IncentiveTableDescriptionType + for _, item := range data.IncentiveTableDescription { + match := searchFilterInItem[model.TariffDescriptionDataType](*item.TariffDescription, filter) + + if match { + result = append(result, item) + } + } + + return result, nil +} + +// return list of constraints +func (i *IncentiveTableCommon) GetConstraints() ([]model.IncentiveTableConstraintsType, error) { + function := model.FunctionTypeIncentiveTableConstraintsData + data, err := featureDataCopyOfType[model.IncentiveTableConstraintsDataType](i.featureLocal, i.featureRemote, function) + if err != nil { + return nil, api.ErrDataNotAvailable + } + + return data.IncentiveTableConstraints, nil +} + +// return current data for Time Series +func (i *IncentiveTableCommon) GetData() ([]model.IncentiveTableType, error) { + function := model.FunctionTypeIncentiveTableData + + data, err := featureDataCopyOfType[model.IncentiveTableDataType](i.featureLocal, i.featureRemote, function) + if err != nil || data == nil || data.IncentiveTable == nil { + return nil, api.ErrDataNotAvailable + } + + return data.IncentiveTable, nil +} diff --git a/features/internal/incentivetable_test.go b/features/internal/incentivetable_test.go new file mode 100644 index 00000000..c9917e55 --- /dev/null +++ b/features/internal/incentivetable_test.go @@ -0,0 +1,219 @@ +package internal_test + +import ( + "testing" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestIncentiveTableSuite(t *testing.T) { + suite.Run(t, new(IncentiveTableSuite)) +} + +type IncentiveTableSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.IncentiveTableCommon +} + +func (s *IncentiveTableSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeIncentiveTable, + functions: []model.FunctionType{ + model.FunctionTypeIncentiveTableDescriptionData, + model.FunctionTypeIncentiveTableConstraintsData, + model.FunctionTypeIncentiveTableData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeIncentiveTable, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalIncentiveTable(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeIncentiveTable, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteIncentiveTable(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *IncentiveTableSuite) Test_GetValues() { + data, err := s.localSut.GetData() + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetData() + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + s.addData() + + data, err = s.localSut.GetData() + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetData() + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) +} + +func (s *IncentiveTableSuite) Test_GetDescriptions() { + filter := model.TariffDescriptionDataType{} + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + s.addDescription() + + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) +} + +func (s *IncentiveTableSuite) Test_GetDescriptionsForScope() { + filter := model.TariffDescriptionDataType{ + ScopeType: util.Ptr(model.ScopeTypeTypeSimpleIncentiveTable), + } + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + s.addDescription() + + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) +} + +func (s *IncentiveTableSuite) Test_GetConstraints() { + data, err := s.localSut.GetConstraints() + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetConstraints() + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + s.addConstraints() + + data, err = s.localSut.GetConstraints() + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetConstraints() + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) +} + +// helpers + +func (s *IncentiveTableSuite) addData() { + fData := &model.IncentiveTableDataType{ + IncentiveTable: []model.IncentiveTableType{ + { + Tariff: &model.TariffDataType{ + TariffId: util.Ptr(model.TariffIdType(0)), + }, + IncentiveSlot: []model.IncentiveTableIncentiveSlotType{ + { + TimeInterval: &model.TimeTableDataType{}, + }, + }, + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeIncentiveTableData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeIncentiveTableData, fData, nil, nil) +} + +func (s *IncentiveTableSuite) addDescription() { + fData := &model.IncentiveTableDescriptionDataType{ + IncentiveTableDescription: []model.IncentiveTableDescriptionType{ + { + TariffDescription: &model.TariffDescriptionDataType{ + TariffId: util.Ptr(model.TariffIdType(0)), + TariffWriteable: util.Ptr(true), + UpdateRequired: util.Ptr(true), + ScopeType: util.Ptr(model.ScopeTypeTypeSimpleIncentiveTable), + }, + Tier: []model.IncentiveTableDescriptionTierType{ + { + TierDescription: &model.TierDescriptionDataType{ + TierId: util.Ptr(model.TierIdType(0)), + TierType: util.Ptr(model.TierTypeTypeDynamicCost), + }, + BoundaryDescription: []model.TierBoundaryDescriptionDataType{ + { + BoundaryId: util.Ptr(model.TierBoundaryIdType(0)), + BoundaryType: util.Ptr(model.TierBoundaryTypeTypePowerBoundary), + BoundaryUnit: util.Ptr(model.UnitOfMeasurementTypeW), + }, + }, + IncentiveDescription: []model.IncentiveDescriptionDataType{ + { + IncentiveId: util.Ptr(model.IncentiveIdType(0)), + IncentiveType: util.Ptr(model.IncentiveTypeTypeAbsoluteCost), + Currency: util.Ptr(model.CurrencyTypeEur), + }, + }, + }, + }, + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeIncentiveTableDescriptionData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeIncentiveTableDescriptionData, fData, nil, nil) +} + +func (s *IncentiveTableSuite) addConstraints() { + fData := &model.IncentiveTableConstraintsDataType{ + IncentiveTableConstraints: []model.IncentiveTableConstraintsType{ + { + Tariff: &model.TariffDataType{ + TariffId: util.Ptr(model.TariffIdType(0)), + }, + TariffConstraints: &model.TariffOverallConstraintsDataType{ + MaxTiersPerTariff: util.Ptr(model.TierCountType(3)), + MaxBoundariesPerTier: util.Ptr(model.TierBoundaryCountType(1)), + MaxIncentivesPerTier: util.Ptr(model.IncentiveCountType(3)), + }, + IncentiveSlotConstraints: &model.TimeTableConstraintsDataType{ + SlotCountMax: util.Ptr(model.TimeSlotCountType(24)), + }, + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeIncentiveTableConstraintsData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeIncentiveTableConstraintsData, fData, nil, nil) +} diff --git a/features/internal/loadcontrol.go b/features/internal/loadcontrol.go new file mode 100644 index 00000000..11c3eaf2 --- /dev/null +++ b/features/internal/loadcontrol.go @@ -0,0 +1,131 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type LoadControlCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalLoadControl(featureLocal spineapi.FeatureLocalInterface) *LoadControlCommon { + return &LoadControlCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteLoadControl(featureRemote spineapi.FeatureRemoteInterface) *LoadControlCommon { + return &LoadControlCommon{ + featureRemote: featureRemote, + } +} + +var _ api.FeatureServerInterface = (*LoadControlCommon)(nil) + +// check if spine.EventPayload Data contains data for a given filter +// +// data type will be checked for model.LoadControlLimitListDataType, +// filter type will be checked for model.LoadControlLimitDescriptionDataType +func (l *LoadControlCommon) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.LoadControlLimitListDataType) + filterData, ok2 := filter.(model.LoadControlLimitDescriptionDataType) + if !ok || !ok2 { + return false + } + + descs, _ := l.GetLimitDescriptionsForFilter(filterData) + for _, desc := range descs { + if desc.LimitId == nil { + continue + } + + for _, item := range data.LoadControlLimitData { + if item.LimitId != nil && + *item.LimitId == *desc.LimitId && + item.Value != nil { + return true + } + } + } + + return false +} + +var _ api.LoadControlCommonInterface = (*LoadControlCommon)(nil) + +// Get the description for a given limitId +// +// Will return nil if no matching description is found +func (l *LoadControlCommon) GetLimitDescriptionForId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDescriptionDataType, error) { + data, err := l.GetLimitDescriptionsForFilter(model.LoadControlLimitDescriptionDataType{LimitId: &limitId}) + + if err != nil || len(data) != 1 { + return nil, api.ErrDataNotAvailable + } + + return &data[0], nil +} + +// Get the description for a given filter +// +// Returns an error if no matching description is found +func (l *LoadControlCommon) GetLimitDescriptionsForFilter( + filter model.LoadControlLimitDescriptionDataType, +) ([]model.LoadControlLimitDescriptionDataType, error) { + function := model.FunctionTypeLoadControlLimitDescriptionListData + + data, err := featureDataCopyOfType[model.LoadControlLimitDescriptionListDataType](l.featureLocal, l.featureRemote, function) + if err != nil || data == nil || data.LoadControlLimitDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.LoadControlLimitDescriptionDataType](data.LoadControlLimitDescriptionData, filter) + return result, nil +} + +// Get the description for a given limitId +// +// Will return nil if no data is available +func (l *LoadControlCommon) GetLimitDataForId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error) { + result, err := l.GetLimitDataForFilter(model.LoadControlLimitDescriptionDataType{LimitId: &limitId}) + if err != nil || len(result) == 0 { + return nil, api.ErrDataNotAvailable + } + return &result[0], nil +} + +// Get limit data for a given filter +// +// Will return nil if no data is available +func (l *LoadControlCommon) GetLimitDataForFilter(filter model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDataType, error) { + function := model.FunctionTypeLoadControlLimitListData + + descriptions, err := l.GetLimitDescriptionsForFilter(filter) + if err != nil || len(descriptions) == 0 { + return nil, api.ErrDataNotAvailable + } + + data, err := featureDataCopyOfType[model.LoadControlLimitListDataType](l.featureLocal, l.featureRemote, function) + if err != nil || data == nil || data.LoadControlLimitData == nil { + return nil, api.ErrDataNotAvailable + } + + var result []model.LoadControlLimitDataType + + for _, desc := range descriptions { + filter2 := model.LoadControlLimitDataType{ + LimitId: desc.LimitId, + } + + elements := searchFilterInList[model.LoadControlLimitDataType](data.LoadControlLimitData, filter2) + result = append(result, elements...) + } + return result, nil +} diff --git a/features/internal/loadcontrol_test.go b/features/internal/loadcontrol_test.go new file mode 100644 index 00000000..e6edffe8 --- /dev/null +++ b/features/internal/loadcontrol_test.go @@ -0,0 +1,355 @@ +package internal_test + +import ( + "testing" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestLoadControlSuite(t *testing.T) { + suite.Run(t, new(LoadControlSuite)) +} + +type LoadControlSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.LoadControlCommon +} + +func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeLoadControl, + functions: []model.FunctionType{ + model.FunctionTypeLoadControlLimitDescriptionListData, + model.FunctionTypeLoadControlLimitConstraintsListData, + model.FunctionTypeLoadControlLimitListData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalLoadControl(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteLoadControl(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *LoadControlSuite) Test_CheckEventPayloadDataForFilter() { + limitType := model.LoadControlLimitTypeTypeMaxValueLimit + scope := model.ScopeTypeTypeSelfConsumption + category := model.LoadControlCategoryTypeObligation + + filter := model.LoadControlLimitDescriptionDataType{ + LimitType: &limitType, + LimitCategory: &category, + ScopeType: &scope, + } + exists := s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + exists = s.localSut.CheckEventPayloadDataForFilter(limitType, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(limitType, filter) + assert.False(s.T(), exists) + + descData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + ScopeType: util.Ptr(scope), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: util.Ptr(category), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + LimitType: util.Ptr(limitType), + ScopeType: util.Ptr(scope), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitCategory: util.Ptr(category), + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + LimitType: util.Ptr(limitType), + ScopeType: util.Ptr(scope), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + LimitCategory: util.Ptr(category), + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + LimitType: util.Ptr(limitType), + ScopeType: util.Ptr(scope), + }, + }, + } + + fErr := s.localFeature.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.remoteFeature.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + + exists = s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + limitData := &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{}, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(limitData, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(limitData, filter) + assert.False(s.T(), exists) + + limitData = &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + Value: model.NewScaledNumberType(16), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + Value: model.NewScaledNumberType(16), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + }, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(limitData, filter) + assert.True(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(limitData, filter) + assert.True(s.T(), exists) +} + +func (s *LoadControlSuite) Test_GetLimitDescriptions() { + filter := model.LoadControlLimitDescriptionDataType{} + data, err := s.localSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *LoadControlSuite) Test_GetLimitDescriptionsForId() { + limitId := model.LoadControlLimitIdType(0) + data, err := s.localSut.GetLimitDescriptionForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDescriptionForId(limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionForId(limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *LoadControlSuite) Test_GetLimitDescriptionsForFilter() { + filter := model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + } + + data, err := s.localSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + filter.LimitType = util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit) + data, err = s.localSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *LoadControlSuite) Test_GetLimitDescriptionsForFilterMeasurementId() { + measurementId := util.Ptr(model.MeasurementIdType(0)) + filter := model.LoadControlLimitDescriptionDataType{ + MeasurementId: measurementId, + } + + data, err := s.localSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + measurementId = util.Ptr(model.MeasurementIdType(10)) + filter = model.LoadControlLimitDescriptionDataType{ + MeasurementId: measurementId, + } + + data, err = s.localSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *LoadControlSuite) Test_GetLimitData() { + filter := model.LoadControlLimitDescriptionDataType{} + data, err := s.localSut.GetLimitDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetLimitDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *LoadControlSuite) Test_GetLimitDataForLimitId() { + limitId := model.LoadControlLimitIdType(0) + data, err := s.localSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetLimitDataForId(limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForId(limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + limitId = model.LoadControlLimitIdType(10) + data, err = s.localSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetLimitDataForId(limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) +} + +// helper + +func (s *LoadControlSuite) addDescription() { + fData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, fData, nil, nil) +} + +func (s *LoadControlSuite) addData() { + fData := &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + IsLimitChangeable: util.Ptr(true), + IsLimitActive: util.Ptr(true), + Value: model.NewScaledNumberType(12), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeLoadControlLimitListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeLoadControlLimitListData, fData, nil, nil) +} diff --git a/features/internal/measurement.go b/features/internal/measurement.go new file mode 100644 index 00000000..2a48cab4 --- /dev/null +++ b/features/internal/measurement.go @@ -0,0 +1,154 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type MeasurementCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalMeasurement(featureLocal spineapi.FeatureLocalInterface) *MeasurementCommon { + return &MeasurementCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteMeasurement(featureRemote spineapi.FeatureRemoteInterface) *MeasurementCommon { + return &MeasurementCommon{ + featureRemote: featureRemote, + } +} + +var _ api.MeasurementCommonInterface = (*MeasurementCommon)(nil) + +// check if spine.EventPayload Data contains data for a given filter +// +// data type will be checked for model.MeasurementListDataType, +// filter type will be checked for model.MeasurementDescriptionDataType +func (m *MeasurementCommon) CheckEventPayloadDataForFilter(payloadData any, filter any) bool { + if payloadData == nil { + return false + } + + data, ok := payloadData.(*model.MeasurementListDataType) + filterData, ok2 := filter.(model.MeasurementDescriptionDataType) + if !ok || !ok2 { + return false + } + + descs, err := m.GetDescriptionsForFilter(filterData) + if err != nil { + return false + } + for _, desc := range descs { + if desc.MeasurementId == nil { + continue + } + + for _, item := range data.MeasurementData { + if item.MeasurementId != nil && + *item.MeasurementId == *desc.MeasurementId && + item.Value != nil { + return true + } + } + } + + return false +} + +// Get the description for a given id +// +// Returns an error if no matching description is found +func (m *MeasurementCommon) GetDescriptionForId( + measurementId model.MeasurementIdType, +) (*model.MeasurementDescriptionDataType, error) { + data, err := m.GetDescriptionsForFilter(model.MeasurementDescriptionDataType{MeasurementId: &measurementId}) + + if err != nil || len(data) != 1 { + return nil, api.ErrDataNotAvailable + } + + return &data[0], nil +} + +// Get the description for a given filter +// +// Returns an error if no matching description is found +func (m *MeasurementCommon) GetDescriptionsForFilter( + filter model.MeasurementDescriptionDataType, +) ([]model.MeasurementDescriptionDataType, error) { + function := model.FunctionTypeMeasurementDescriptionListData + + data, err := featureDataCopyOfType[model.MeasurementDescriptionListDataType](m.featureLocal, m.featureRemote, function) + if err != nil || data == nil || data.MeasurementDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.MeasurementDescriptionDataType](data.MeasurementDescriptionData, filter) + return result, nil +} + +// Get the constraints for a given filter +// +// Returns an error if no matching constraint is found +func (m *MeasurementCommon) GetConstraintsForFilter( + filter model.MeasurementConstraintsDataType, +) ([]model.MeasurementConstraintsDataType, error) { + function := model.FunctionTypeMeasurementConstraintsListData + + data, err := featureDataCopyOfType[model.MeasurementConstraintsListDataType](m.featureLocal, m.featureRemote, function) + if err != nil || data == nil || data.MeasurementConstraintsData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.MeasurementConstraintsDataType](data.MeasurementConstraintsData, filter) + return result, nil +} + +// Get the measuement data for a given measurementId +// +// Will return nil if no data is available +func (m *MeasurementCommon) GetDataForId(measurementId model.MeasurementIdType) ( + *model.MeasurementDataType, error) { + result, err := m.GetDataForFilter(model.MeasurementDescriptionDataType{MeasurementId: &measurementId}) + if err != nil || len(result) == 0 { + return nil, api.ErrDataNotAvailable + } + + return &result[0], nil +} + +// Get measuement data for a given filter +// +// Will return nil if no data is available +func (m *MeasurementCommon) GetDataForFilter(filter model.MeasurementDescriptionDataType) ( + []model.MeasurementDataType, error) { + function := model.FunctionTypeMeasurementListData + + descriptions, err := m.GetDescriptionsForFilter(filter) + if err != nil || len(descriptions) == 0 { + return nil, api.ErrDataNotAvailable + } + + data, err := featureDataCopyOfType[model.MeasurementListDataType](m.featureLocal, m.featureRemote, function) + if err != nil || data == nil || data.MeasurementData == nil { + return nil, api.ErrDataNotAvailable + } + + var result []model.MeasurementDataType + + for _, desc := range descriptions { + filter2 := model.MeasurementDataType{ + MeasurementId: desc.MeasurementId, + } + + elements := searchFilterInList[model.MeasurementDataType](data.MeasurementData, filter2) + result = append(result, elements...) + } + return result, nil +} diff --git a/features/internal/measurement_test.go b/features/internal/measurement_test.go new file mode 100644 index 00000000..3e681c9f --- /dev/null +++ b/features/internal/measurement_test.go @@ -0,0 +1,371 @@ +package internal_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestMeasurementSuite(t *testing.T) { + suite.Run(t, new(MeasurementSuite)) +} + +type MeasurementSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.MeasurementCommon +} + +func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeMeasurement, + functions: []model.FunctionType{ + model.FunctionTypeMeasurementDescriptionListData, + model.FunctionTypeMeasurementConstraintsListData, + model.FunctionTypeMeasurementListData, + }, + }, + { + featureType: model.FeatureTypeTypeElectricalConnection, + functions: []model.FunctionType{ + model.FunctionTypeElectricalConnectionDescriptionListData, + model.FunctionTypeElectricalConnectionParameterDescriptionListData, + model.FunctionTypeElectricalConnectionPermittedValueSetListData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalMeasurement(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteMeasurement(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *MeasurementSuite) Test_MeasurementCheckPayloadDataForScope() { + scopeType := model.ScopeTypeTypeACPower + filter := model.MeasurementDescriptionDataType{ + ScopeType: &scopeType, + } + exists := s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + exists = s.localSut.CheckEventPayloadDataForFilter(scopeType, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(scopeType, filter) + assert.False(s.T(), exists) + + descData := &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + { + ScopeType: util.Ptr(model.ScopeTypeTypeACPower), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + ScopeType: util.Ptr(model.ScopeTypeTypeACPower), + }, + }, + } + + fErr := s.localFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + fErr = s.remoteFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, descData, nil, nil) + assert.Nil(s.T(), fErr) + + exists = s.localSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + data := &model.MeasurementListDataType{ + MeasurementData: []model.MeasurementDataType{ + {}, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(data, filter) + assert.False(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(data, filter) + assert.False(s.T(), exists) + + data = &model.MeasurementListDataType{ + MeasurementData: []model.MeasurementDataType{ + { + Value: model.NewScaledNumberType(80), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + Value: model.NewScaledNumberType(80), + }, + }, + } + + exists = s.localSut.CheckEventPayloadDataForFilter(data, filter) + assert.True(s.T(), exists) + exists = s.remoteSut.CheckEventPayloadDataForFilter(data, filter) + assert.True(s.T(), exists) +} + +func (s *MeasurementSuite) Test_GetValueForMeasurementId() { + measurement := model.MeasurementIdType(0) + + data, err := s.localSut.GetDataForId(measurement) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForId(measurement) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDataForId(measurement) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForId(measurement) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetDataForId(measurement) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 9.0, data.Value.GetValue()) + data, err = s.remoteSut.GetDataForId(measurement) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 9.0, data.Value.GetValue()) + + data, err = s.localSut.GetDataForId(model.MeasurementIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForId(model.MeasurementIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *MeasurementSuite) Test_GetValuesForTypeCommodityScope() { + measurement := model.MeasurementTypeTypeCurrent + commodity := model.CommodityTypeTypeElectricity + scope := model.ScopeTypeTypeACCurrent + + filter := model.MeasurementDescriptionDataType{ + MeasurementType: &measurement, + CommodityType: &commodity, + ScopeType: &scope, + } + + data, err := s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + measurement = model.MeasurementTypeTypeArea + data, err = s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) +} + +func (s *MeasurementSuite) Test_GetDescriptionsForId() { + measurementId := model.MeasurementIdType(0) + data, err := s.localSut.GetDescriptionForId(measurementId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionForId(measurementId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDescriptionForId(measurementId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionForId(measurementId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *MeasurementSuite) Test_GetDescriptionsForScope() { + filter := model.MeasurementDescriptionDataType{ + ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + } + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addDescription() + + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *MeasurementSuite) Test_GetConstraints() { + filter := model.MeasurementConstraintsDataType{} + data, err := s.localSut.GetConstraintsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetConstraintsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addConstraints() + + data, err = s.localSut.GetConstraintsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetConstraintsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *MeasurementSuite) Test_GetValues() { + filter := model.MeasurementDescriptionDataType{} + data, err := s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addConstraints() + + s.addDescription() + + data, err = s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + s.addData() + + data, err = s.localSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +// helper + +func (s *MeasurementSuite) addDescription() { + fData := &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + { + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + MeasurementType: util.Ptr(model.MeasurementTypeTypePercentage), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + ScopeType: util.Ptr(model.ScopeTypeTypeStateOfCharge), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeMeasurementDescriptionListData, fData, nil, nil) +} + +func (s *MeasurementSuite) addConstraints() { + fData := &model.MeasurementConstraintsListDataType{ + MeasurementConstraintsData: []model.MeasurementConstraintsDataType{ + { + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + ValueRangeMin: model.NewScaledNumberType(2), + ValueRangeMax: model.NewScaledNumberType(16), + ValueStepSize: model.NewScaledNumberType(0.1), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + ValueRangeMin: model.NewScaledNumberType(0), + ValueRangeMax: model.NewScaledNumberType(100), + ValueStepSize: model.NewScaledNumberType(0.1), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeMeasurementConstraintsListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeMeasurementConstraintsListData, fData, nil, nil) +} + +func (s *MeasurementSuite) addData() { + t := time.Now().UTC() + fData := &model.MeasurementListDataType{ + MeasurementData: []model.MeasurementDataType{ + { + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + Value: model.NewScaledNumberType(9), + Timestamp: model.NewAbsoluteOrRelativeTimeTypeFromTime(t), + }, + { + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + Value: model.NewScaledNumberType(9), + Timestamp: model.NewAbsoluteOrRelativeTimeTypeFromTime(t), + }, + }, + } + s.localFeature.UpdateData(model.FunctionTypeMeasurementListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeMeasurementListData, fData, nil, nil) +} diff --git a/features/internal/smartenergymanagementps.go b/features/internal/smartenergymanagementps.go new file mode 100644 index 00000000..09745631 --- /dev/null +++ b/features/internal/smartenergymanagementps.go @@ -0,0 +1,38 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type SmartEnergyManagementPsCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalSmartEnergyManagementPs(featureLocal spineapi.FeatureLocalInterface) *SmartEnergyManagementPsCommon { + return &SmartEnergyManagementPsCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteSmartEnergyManagementPs(featureRemote spineapi.FeatureRemoteInterface) *SmartEnergyManagementPsCommon { + return &SmartEnergyManagementPsCommon{ + featureRemote: featureRemote, + } +} + +var _ api.FeatureServerInterface = (*SmartEnergyManagementPsCommon)(nil) + +// return current data for FunctionTypeSmartEnergyManagementPsData +func (i *SmartEnergyManagementPsCommon) GetData() (*model.SmartEnergyManagementPsDataType, error) { + function := model.FunctionTypeSmartEnergyManagementPsData + + data, err := featureDataCopyOfType[model.SmartEnergyManagementPsDataType](i.featureLocal, i.featureRemote, function) + if err != nil || data == nil { + return nil, api.ErrDataNotAvailable + } + + return data, nil +} diff --git a/features/internal/smartenergymanagementps_test.go b/features/internal/smartenergymanagementps_test.go new file mode 100644 index 00000000..b8edb6ce --- /dev/null +++ b/features/internal/smartenergymanagementps_test.go @@ -0,0 +1,87 @@ +package internal_test + +import ( + "testing" + + "github.com/enbility/eebus-go/features/internal" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestSmartEnergyManagementPsSuite(t *testing.T) { + suite.Run(t, new(SmartEnergyManagementPsSuite)) +} + +type SmartEnergyManagementPsSuite struct { + suite.Suite + + localEntity spineapi.EntityLocalInterface + remoteEntity spineapi.EntityRemoteInterface + + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface + + localSut, + remoteSut *internal.SmartEnergyManagementPsCommon +} + +func (s *SmartEnergyManagementPsSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + + s.localEntity, s.remoteEntity = setupFeatures( + s.T(), + mockWriter, + []featureFunctions{ + { + featureType: model.FeatureTypeTypeSmartEnergyManagementPs, + functions: []model.FunctionType{ + model.FunctionTypeSmartEnergyManagementPsData, + }, + }, + }, + ) + + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeSmartEnergyManagementPs, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalSmartEnergyManagementPs(s.localFeature) + assert.NotNil(s.T(), s.localSut) + + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeSmartEnergyManagementPs, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteSmartEnergyManagementPs(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) +} + +func (s *SmartEnergyManagementPsSuite) Test_GetData() { + value, err := s.localSut.GetData() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + value, err = s.remoteSut.GetData() + assert.NotNil(s.T(), err) + assert.Nil(s.T(), value) + + s.addData() + + value, err = s.localSut.GetData() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) + value, err = s.remoteSut.GetData() + assert.Nil(s.T(), err) + assert.NotNil(s.T(), value) +} + +// helper + +func (s *SmartEnergyManagementPsSuite) addData() { + fData := &model.SmartEnergyManagementPsDataType{ + NodeScheduleInformation: &model.PowerSequenceNodeScheduleInformationDataType{}, + Alternatives: []model.SmartEnergyManagementPsAlternativesType{}, + } + s.localFeature.UpdateData(model.FunctionTypeSmartEnergyManagementPsData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeSmartEnergyManagementPsData, fData, nil, nil) +} diff --git a/features/internal/timeseries.go b/features/internal/timeseries.go new file mode 100644 index 00000000..8317bd8d --- /dev/null +++ b/features/internal/timeseries.go @@ -0,0 +1,80 @@ +package internal + +import ( + "github.com/enbility/eebus-go/api" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type TimeSeriesCommon struct { + featureLocal spineapi.FeatureLocalInterface + featureRemote spineapi.FeatureRemoteInterface +} + +func NewLocalTimeSeries(featureLocal spineapi.FeatureLocalInterface) *TimeSeriesCommon { + return &TimeSeriesCommon{ + featureLocal: featureLocal, + } +} + +func NewRemoteTimeSeries(featureRemote spineapi.FeatureRemoteInterface) *TimeSeriesCommon { + return &TimeSeriesCommon{ + featureRemote: featureRemote, + } +} + +var _ api.TimeSeriesCommonInterface = (*TimeSeriesCommon)(nil) + +// return list of descriptions for a given filter +func (t *TimeSeriesCommon) GetDescriptionsForFilter( + filter model.TimeSeriesDescriptionDataType, +) ([]model.TimeSeriesDescriptionDataType, error) { + function := model.FunctionTypeTimeSeriesDescriptionListData + + data, err := featureDataCopyOfType[model.TimeSeriesDescriptionListDataType](t.featureLocal, t.featureRemote, function) + if err != nil || data == nil || data.TimeSeriesDescriptionData == nil { + return nil, api.ErrDataNotAvailable + } + + result := searchFilterInList[model.TimeSeriesDescriptionDataType](data.TimeSeriesDescriptionData, filter) + return result, nil +} + +// return current constraints for Time Series +func (t *TimeSeriesCommon) GetConstraints() ([]model.TimeSeriesConstraintsDataType, error) { + function := model.FunctionTypeTimeSeriesConstraintsListData + + data, err := featureDataCopyOfType[model.TimeSeriesConstraintsListDataType](t.featureLocal, t.featureRemote, function) + if err != nil { + return nil, api.ErrDataNotAvailable + } + + return data.TimeSeriesConstraintsData, nil +} + +// return current data for Time Series for a given filter +func (t *TimeSeriesCommon) GetDataForFilter(filter model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDataType, error) { + function := model.FunctionTypeTimeSeriesListData + + descriptions, err := t.GetDescriptionsForFilter(filter) + if err != nil || len(descriptions) == 0 { + return nil, api.ErrDataNotAvailable + } + + data, err := featureDataCopyOfType[model.TimeSeriesListDataType](t.featureLocal, t.featureRemote, function) + if err != nil || data == nil || data.TimeSeriesData == nil { + return nil, api.ErrDataNotAvailable + } + + var result []model.TimeSeriesDataType + + for _, desc := range descriptions { + filter2 := model.TimeSeriesDataType{ + TimeSeriesId: desc.TimeSeriesId, + } + + elements := searchFilterInList[model.TimeSeriesDataType](data.TimeSeriesData, filter2) + result = append(result, elements...) + } + return result, nil +} diff --git a/features/timeseries_test.go b/features/internal/timeseries_test.go similarity index 51% rename from features/timeseries_test.go rename to features/internal/timeseries_test.go index a396b31d..7d984454 100644 --- a/features/timeseries_test.go +++ b/features/internal/timeseries_test.go @@ -1,15 +1,16 @@ -package features_test +package internal_test import ( "testing" "time" - "github.com/enbility/eebus-go/features" + "github.com/enbility/eebus-go/features/internal" "github.com/enbility/eebus-go/util" - shipapi "github.com/enbility/ship-go/api" + shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" ) @@ -23,20 +24,20 @@ type TimeSeriesSuite struct { localEntity spineapi.EntityLocalInterface remoteEntity spineapi.EntityRemoteInterface - timeSeries *features.TimeSeries - sentMessage []byte -} - -var _ shipapi.ShipConnectionDataWriterInterface = (*TimeSeriesSuite)(nil) + localFeature spineapi.FeatureLocalInterface + remoteFeature spineapi.FeatureRemoteInterface -func (s *TimeSeriesSuite) WriteShipMessageWithPayload(message []byte) { - s.sentMessage = message + localSut, + remoteSut *internal.TimeSeriesCommon } func (s *TimeSeriesSuite) BeforeTest(suiteName, testName string) { + mockWriter := shipmocks.NewShipConnectionDataWriterInterface(s.T()) + mockWriter.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + s.localEntity, s.remoteEntity = setupFeatures( s.T(), - s, + mockWriter, []featureFunctions{ { featureType: model.FeatureTypeTypeTimeSeries, @@ -49,134 +50,158 @@ func (s *TimeSeriesSuite) BeforeTest(suiteName, testName string) { }, ) - var err error - s.timeSeries, err = features.NewTimeSeries(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.timeSeries) -} - -func (s *TimeSeriesSuite) Test_RequestDescription() { - msgCounter, err := s.timeSeries.RequestDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), msgCounter) -} - -func (s *TimeSeriesSuite) Test_RequestConstraints() { - msgCounter, err := s.timeSeries.RequestConstraints() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), msgCounter) -} + s.localFeature = s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeTimeSeries, model.RoleTypeServer) + assert.NotNil(s.T(), s.localFeature) + s.localSut = internal.NewLocalTimeSeries(s.localFeature) + assert.NotNil(s.T(), s.localSut) -func (s *TimeSeriesSuite) Test_RequestValues() { - counter, err := s.timeSeries.RequestValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) + s.remoteFeature = s.remoteEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeTimeSeries, model.RoleTypeServer) + assert.NotNil(s.T(), s.remoteFeature) + s.remoteSut = internal.NewRemoteTimeSeries(s.remoteFeature) + assert.NotNil(s.T(), s.remoteSut) } -func (s *TimeSeriesSuite) Test_WriteValues() { - counter, err := s.timeSeries.WriteValues(nil) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data := []model.TimeSeriesDataType{} - counter, err = s.timeSeries.WriteValues(data) +func (s *TimeSeriesSuite) Test_GetData() { + filter := model.TimeSeriesDescriptionDataType{} + data, err := s.localSut.GetDataForFilter(filter) assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data = []model.TimeSeriesDataType{ - { - TimeSeriesId: util.Ptr(model.TimeSeriesIdType(1)), - }, - } - counter, err = s.timeSeries.WriteValues(data) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *TimeSeriesSuite) Test_GetValues() { - data, err := s.timeSeries.GetValues() + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetDataForFilter(filter) assert.NotNil(s.T(), err) assert.Equal(s.T(), 0, len(data)) + s.addDescription() s.addData() - data, err = s.timeSeries.GetValues() + data, err = s.localSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetDataForFilter(filter) assert.Nil(s.T(), err) assert.NotEqual(s.T(), nil, data) } -func (s *TimeSeriesSuite) Test_GetValuesForId() { - data, err := s.timeSeries.GetValueForType(model.TimeSeriesTypeTypeSingleDemand) +func (s *TimeSeriesSuite) Test_GetDataForId() { + filter := model.TimeSeriesDescriptionDataType{ + TimeSeriesType: util.Ptr(model.TimeSeriesTypeTypeSingleDemand), + } + data, err := s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) assert.NotNil(s.T(), err) assert.Nil(s.T(), data) s.addData() - data, err = s.timeSeries.GetValueForType(model.TimeSeriesTypeTypeSingleDemand) + data, err = s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) assert.NotNil(s.T(), err) assert.Nil(s.T(), data) s.addDescription() - data, err = s.timeSeries.GetValueForType(model.TimeSeriesTypeTypeSingleDemand) + data, err = s.localSut.GetDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) assert.Nil(s.T(), err) assert.NotNil(s.T(), data) - data, err = s.timeSeries.GetValueForType(model.TimeSeriesTypeTypePlan) + filter.TimeSeriesType = util.Ptr(model.TimeSeriesTypeTypePlan) + data, err = s.localSut.GetDataForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDataForFilter(filter) assert.NotNil(s.T(), err) assert.Nil(s.T(), data) } func (s *TimeSeriesSuite) Test_GetDescriptions() { - data, err := s.timeSeries.GetDescriptions() + filter := model.TimeSeriesDescriptionDataType{} + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.NotNil(s.T(), err) assert.Equal(s.T(), 0, len(data)) s.addDescription() - data, err = s.timeSeries.GetDescriptions() + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.Nil(s.T(), err) assert.NotEqual(s.T(), nil, data) } func (s *TimeSeriesSuite) Test_GetDescriptionsForId() { - id := model.TimeSeriesIdType(0) - data, err := s.timeSeries.GetDescriptionForId(id) + filter := model.TimeSeriesDescriptionDataType{ + TimeSeriesId: util.Ptr(model.TimeSeriesIdType(0)), + } + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.NotNil(s.T(), err) assert.Nil(s.T(), data) s.addDescription() - data, err = s.timeSeries.GetDescriptionForId(id) + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.Nil(s.T(), err) assert.NotNil(s.T(), data) - id = model.TimeSeriesIdType(1) - data, err = s.timeSeries.GetDescriptionForId(id) - assert.NotNil(s.T(), err) + filter.TimeSeriesId = util.Ptr(model.TimeSeriesIdType(1)) + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) assert.Nil(s.T(), data) } func (s *TimeSeriesSuite) Test_GetDescriptionForType() { - data, err := s.timeSeries.GetDescriptionForType(model.TimeSeriesTypeTypeSingleDemand) + filter := model.TimeSeriesDescriptionDataType{ + TimeSeriesType: util.Ptr(model.TimeSeriesTypeTypeSingleDemand), + } + data, err := s.localSut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.NotNil(s.T(), err) assert.Nil(s.T(), data) s.addDescription() - data, err = s.timeSeries.GetDescriptionForType(model.TimeSeriesTypeTypeSingleDemand) + data, err = s.localSut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + data, err = s.remoteSut.GetDescriptionsForFilter(filter) assert.Nil(s.T(), err) assert.NotNil(s.T(), data) } func (s *TimeSeriesSuite) Test_GetConstraints() { - data, err := s.timeSeries.GetConstraints() + data, err := s.localSut.GetConstraints() + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + data, err = s.remoteSut.GetConstraints() assert.NotNil(s.T(), err) assert.Equal(s.T(), 0, len(data)) s.addConstraints() - data, err = s.timeSeries.GetConstraints() + data, err = s.localSut.GetConstraints() + assert.Nil(s.T(), err) + assert.NotEqual(s.T(), nil, data) + data, err = s.remoteSut.GetConstraints() assert.Nil(s.T(), err) assert.NotEqual(s.T(), nil, data) } @@ -184,8 +209,6 @@ func (s *TimeSeriesSuite) Test_GetConstraints() { // helpers func (s *TimeSeriesSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.TimeSeriesListDataType{ TimeSeriesData: []model.TimeSeriesDataType{ { @@ -210,11 +233,11 @@ func (s *TimeSeriesSuite) addData() { }, }, } - rF.UpdateData(model.FunctionTypeTimeSeriesListData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeTimeSeriesListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeTimeSeriesListData, fData, nil, nil) } func (s *TimeSeriesSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) fData := &model.TimeSeriesDescriptionListDataType{ TimeSeriesDescriptionData: []model.TimeSeriesDescriptionDataType{ { @@ -227,11 +250,11 @@ func (s *TimeSeriesSuite) addDescription() { }, }, } - rF.UpdateData(model.FunctionTypeTimeSeriesDescriptionListData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeTimeSeriesDescriptionListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeTimeSeriesDescriptionListData, fData, nil, nil) } func (s *TimeSeriesSuite) addConstraints() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) fData := &model.TimeSeriesConstraintsListDataType{ TimeSeriesConstraintsData: []model.TimeSeriesConstraintsDataType{ { @@ -249,5 +272,6 @@ func (s *TimeSeriesSuite) addConstraints() { }, }, } - rF.UpdateData(model.FunctionTypeTimeSeriesConstraintsListData, fData, nil, nil) + s.localFeature.UpdateData(model.FunctionTypeTimeSeriesConstraintsListData, fData, nil, nil) + s.remoteFeature.UpdateData(model.FunctionTypeTimeSeriesConstraintsListData, fData, nil, nil) } diff --git a/features/loadcontrol.go b/features/loadcontrol.go deleted file mode 100644 index 16d08d14..00000000 --- a/features/loadcontrol.go +++ /dev/null @@ -1,182 +0,0 @@ -package features - -import ( - "github.com/enbility/eebus-go/api" - "github.com/enbility/eebus-go/util" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type LoadControl struct { - *Feature -} - -// Get a new LoadControl features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewLoadControl( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*LoadControl, error) { - feature, err := NewFeature(model.FeatureTypeTypeLoadControl, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - lc := &LoadControl{ - Feature: feature, - } - - return lc, nil -} - -// request FunctionTypeLoadControlLimitDescriptionListData from a remote device -func (l *LoadControl) RequestLimitDescriptions() (*model.MsgCounterType, error) { - return l.requestData(model.FunctionTypeLoadControlLimitDescriptionListData, nil, nil) -} - -// request FunctionTypeLoadControlLimitConstraintsListData from a remote device -func (l *LoadControl) RequestLimitConstraints() (*model.MsgCounterType, error) { - return l.requestData(model.FunctionTypeLoadControlLimitConstraintsListData, nil, nil) -} - -// request FunctionTypeLoadControlLimitListData from a remote device -func (l *LoadControl) RequestLimitValues() (*model.MsgCounterType, error) { - return l.requestData(model.FunctionTypeLoadControlLimitListData, nil, nil) -} - -// returns the load control limit descriptions -// returns an error if no description data is available yet -func (l *LoadControl) GetLimitDescriptions() ([]model.LoadControlLimitDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.LoadControlLimitDescriptionListDataType](l.featureRemote, model.FunctionTypeLoadControlLimitDescriptionListData) - if err != nil { - return nil, api.ErrMetadataNotAvailable - } - - return data.LoadControlLimitDescriptionData, nil -} - -// returns the load control limit descriptions of a provided category -// returns an error if no description data for the category is available -func (l *LoadControl) GetLimitDescriptionsForCategory(category model.LoadControlCategoryType) ([]model.LoadControlLimitDescriptionDataType, error) { - data, err := l.GetLimitDescriptions() - if err != nil { - return nil, err - } - - var result []model.LoadControlLimitDescriptionDataType - - for _, item := range data { - if item.LimitId != nil && item.LimitCategory != nil && *item.LimitCategory == category { - result = append(result, item) - } - } - - if len(result) == 0 { - return nil, api.ErrDataNotAvailable - } - - return result, nil -} - -// returns the load control limit descriptions of a provided type, direction and scope -// returns an error if no description data for the category is available -// -// providing an empty string for any of the params, will ignore the value in the request -func (l *LoadControl) GetLimitDescriptionsForTypeCategoryDirectionScope( - limitType model.LoadControlLimitTypeType, - limitCategory model.LoadControlCategoryType, - limitDirection model.EnergyDirectionType, - scope model.ScopeTypeType, -) ([]model.LoadControlLimitDescriptionDataType, error) { - data, err := l.GetLimitDescriptions() - if err != nil || len(data) == 0 { - return nil, err - } - - var result []model.LoadControlLimitDescriptionDataType - - for _, item := range data { - if item.LimitId != nil && - (limitType == "" || (item.LimitType != nil && *item.LimitType == limitType)) && - (limitCategory == "" || (item.LimitCategory != nil && *item.LimitCategory == limitCategory)) && - (limitDirection == "" || (item.LimitDirection != nil && *item.LimitDirection == limitDirection)) && - (scope == "" || (item.ScopeType != nil && *item.ScopeType == scope)) { - result = append(result, item) - } - } - - if len(result) == 0 { - return nil, api.ErrDataNotAvailable - } - - return result, nil -} - -// returns the load control limit descriptions for a provided measurementId -// returns an error if no description data for the measurementId is available -func (l *LoadControl) GetLimitDescriptionsForMeasurementId(measurementId model.MeasurementIdType) ([]model.LoadControlLimitDescriptionDataType, error) { - data, err := l.GetLimitDescriptions() - if err != nil { - return nil, err - } - - var result []model.LoadControlLimitDescriptionDataType - - for _, item := range data { - if item.LimitId != nil && item.MeasurementId != nil && *item.MeasurementId == measurementId { - result = append(result, item) - } - } - - if len(result) == 0 { - return nil, api.ErrDataNotAvailable - } - - return result, nil -} - -// write load control limits -// returns an error if this failed -func (l *LoadControl) WriteLimitValues(data []model.LoadControlLimitDataType) (*model.MsgCounterType, error) { - if len(data) == 0 { - return nil, api.ErrMissingData - } - - cmd := model.CmdType{ - Function: util.Ptr(model.FunctionTypeLoadControlLimitListData), - Filter: []model.FilterType{*model.NewFilterTypePartial()}, - LoadControlLimitListData: &model.LoadControlLimitListDataType{ - LoadControlLimitData: data, - }, - } - - return l.remoteDevice.Sender().Write(l.featureLocal.Address(), l.featureRemote.Address(), cmd) -} - -// return limit data -func (l *LoadControl) GetLimitValues() ([]model.LoadControlLimitDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.LoadControlLimitListDataType](l.featureRemote, model.FunctionTypeLoadControlLimitListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.LoadControlLimitData, nil -} - -// return limit values -func (l *LoadControl) GetLimitValueForLimitId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error) { - data, err := l.GetLimitValues() - if err != nil { - return nil, err - } - - for _, item := range data { - if item.LimitId != nil && *item.LimitId == limitId { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} diff --git a/features/loadcontrol_test.go b/features/loadcontrol_test.go deleted file mode 100644 index fa6b6928..00000000 --- a/features/loadcontrol_test.go +++ /dev/null @@ -1,244 +0,0 @@ -package features_test - -import ( - "testing" - - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" - shipapi "github.com/enbility/ship-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -func TestLoadControlSuite(t *testing.T) { - suite.Run(t, new(LoadControlSuite)) -} - -type LoadControlSuite struct { - suite.Suite - - localEntity spineapi.EntityLocalInterface - remoteEntity spineapi.EntityRemoteInterface - - loadControl *features.LoadControl - sentMessage []byte -} - -var _ shipapi.ShipConnectionDataWriterInterface = (*LoadControlSuite)(nil) - -func (s *LoadControlSuite) WriteShipMessageWithPayload(message []byte) { - s.sentMessage = message -} - -func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { - s.localEntity, s.remoteEntity = setupFeatures( - s.T(), - s, - []featureFunctions{ - { - featureType: model.FeatureTypeTypeLoadControl, - functions: []model.FunctionType{ - model.FunctionTypeLoadControlLimitDescriptionListData, - model.FunctionTypeLoadControlLimitConstraintsListData, - model.FunctionTypeLoadControlLimitListData, - }, - }, - }, - ) - - var err error - s.loadControl, err = features.NewLoadControl(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.loadControl) -} - -func (s *LoadControlSuite) Test_RequestLimitDescription() { - counter, err := s.loadControl.RequestLimitDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *LoadControlSuite) Test_RequestLimitConstraints() { - counter, err := s.loadControl.RequestLimitConstraints() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *LoadControlSuite) Test_RequestLimits() { - counter, err := s.loadControl.RequestLimitValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *LoadControlSuite) Test_GetLimitDescriptions() { - data, err := s.loadControl.GetLimitDescriptions() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *LoadControlSuite) Test_GetLimitDescriptionsForCategory() { - data, err := s.loadControl.GetLimitDescriptionsForCategory(model.LoadControlCategoryTypeObligation) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitDescriptionsForCategory(model.LoadControlCategoryTypeOptimization) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - data, err = s.loadControl.GetLimitDescriptionsForCategory(model.LoadControlCategoryTypeObligation) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *LoadControlSuite) Test_GetLimitDescriptionsForTypeDirectionScope() { - data, err := s.loadControl.GetLimitDescriptionsForTypeCategoryDirectionScope( - model.LoadControlLimitTypeTypeSignDependentAbsValueLimit, - model.LoadControlCategoryTypeObligation, - model.EnergyDirectionTypeConsume, - model.ScopeTypeTypeActivePowerLimit) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitDescriptionsForTypeCategoryDirectionScope( - model.LoadControlLimitTypeTypeMaxValueLimit, - model.LoadControlCategoryTypeObligation, - model.EnergyDirectionTypeConsume, - model.ScopeTypeTypeActivePowerLimit) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - data, err = s.loadControl.GetLimitDescriptionsForTypeCategoryDirectionScope( - model.LoadControlLimitTypeTypeSignDependentAbsValueLimit, - model.LoadControlCategoryTypeObligation, - model.EnergyDirectionTypeConsume, - model.ScopeTypeTypeActivePowerLimit) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *LoadControlSuite) Test_GetLimitDescriptionsForMeasurementId() { - measurementId := model.MeasurementIdType(0) - data, err := s.loadControl.GetLimitDescriptionsForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitDescriptionsForMeasurementId(measurementId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - measurementId = model.MeasurementIdType(10) - data, err = s.loadControl.GetLimitDescriptionsForMeasurementId(measurementId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *LoadControlSuite) Test_WriteLimitValues() { - counter, err := s.loadControl.WriteLimitValues(nil) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data := []model.LoadControlLimitDataType{} - counter, err = s.loadControl.WriteLimitValues(data) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), counter) - - data = []model.LoadControlLimitDataType{ - { - LimitId: util.Ptr(model.LoadControlLimitIdType(0)), - Value: model.NewScaledNumberType(10), - }, - } - counter, err = s.loadControl.WriteLimitValues(data) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *LoadControlSuite) Test_GetLimitData() { - data, err := s.loadControl.GetLimitValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.loadControl.GetLimitValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *LoadControlSuite) Test_GetLimitDataForLimitId() { - limitId := model.LoadControlLimitIdType(0) - data, err := s.loadControl.GetLimitValueForLimitId(limitId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.loadControl.GetLimitValueForLimitId(limitId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.loadControl.GetLimitValueForLimitId(limitId) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - limitId = model.LoadControlLimitIdType(10) - data, err = s.loadControl.GetLimitValueForLimitId(limitId) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -// helper - -func (s *LoadControlSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.LoadControlLimitDescriptionListDataType{ - LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ - { - LimitId: util.Ptr(model.LoadControlLimitIdType(0)), - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), - LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), - LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), - ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), - }, - }, - } - rF.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, fData, nil, nil) -} - -func (s *LoadControlSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.LoadControlLimitListDataType{ - LoadControlLimitData: []model.LoadControlLimitDataType{ - { - LimitId: util.Ptr(model.LoadControlLimitIdType(0)), - IsLimitChangeable: util.Ptr(true), - IsLimitActive: util.Ptr(true), - Value: model.NewScaledNumberType(12), - }, - }, - } - rF.UpdateData(model.FunctionTypeLoadControlLimitListData, fData, nil, nil) -} diff --git a/features/measurement.go b/features/measurement.go deleted file mode 100644 index 5cba18ea..00000000 --- a/features/measurement.go +++ /dev/null @@ -1,171 +0,0 @@ -package features - -import ( - "github.com/enbility/eebus-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type Measurement struct { - *Feature -} - -// Get a new Measurement features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewMeasurement( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*Measurement, error) { - feature, err := NewFeature(model.FeatureTypeTypeMeasurement, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - m := &Measurement{ - Feature: feature, - } - - return m, nil -} - -// request FunctionTypeMeasurementDescriptionListData from a remote device -func (m *Measurement) RequestDescriptions() (*model.MsgCounterType, error) { - return m.requestData(model.FunctionTypeMeasurementDescriptionListData, nil, nil) -} - -// request FunctionTypeMeasurementConstraintsListData from a remote entity -func (m *Measurement) RequestConstraints() (*model.MsgCounterType, error) { - return m.requestData(model.FunctionTypeMeasurementConstraintsListData, nil, nil) -} - -// request FunctionTypeMeasurementListData from a remote entity -func (m *Measurement) RequestValues() (*model.MsgCounterType, error) { - return m.requestData(model.FunctionTypeMeasurementListData, nil, nil) -} - -// return list of descriptions -func (m *Measurement) GetDescriptions() ([]model.MeasurementDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.MeasurementDescriptionListDataType](m.featureRemote, model.FunctionTypeMeasurementDescriptionListData) - if err != nil { - return nil, api.ErrMetadataNotAvailable - } - - return data.MeasurementDescriptionData, nil -} - -// return a list of MeasurementDescriptionDataType for a given scope -func (m *Measurement) GetDescriptionsForScope(scope model.ScopeTypeType) ([]model.MeasurementDescriptionDataType, error) { - data, err := m.GetDescriptions() - if err != nil { - return nil, err - } - - var result []model.MeasurementDescriptionDataType - for _, item := range data { - if item.ScopeType != nil && *item.ScopeType == scope { - result = append(result, item) - } - } - - if len(result) == 0 { - return nil, api.ErrDataNotAvailable - } - - return result, nil -} - -// return current electrical description for a given measurementId -func (m *Measurement) GetDescriptionForMeasurementId(measurementId model.MeasurementIdType) (*model.MeasurementDescriptionDataType, error) { - descriptions, err := m.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range descriptions { - if item.MeasurementId == nil || - *item.MeasurementId != measurementId { - continue - } - - return &item, nil - } - - return nil, api.ErrMetadataNotAvailable -} - -// return current values for measurements -func (m *Measurement) GetValues() ([]model.MeasurementDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.MeasurementListDataType](m.featureRemote, model.FunctionTypeMeasurementListData) - if err != nil { - return nil, api.ErrMetadataNotAvailable - } - - return data.MeasurementData, nil -} - -// return current values of a measurementId -// -// if nothing is found, it will return an error -func (m *Measurement) GetValueForMeasurementId(id model.MeasurementIdType) (float64, error) { - values, err := m.GetValues() - if err != nil { - return 0, err - } - - for _, item := range values { - if item.MeasurementId == nil || item.Value == nil { - continue - } - - if *item.MeasurementId == id { - return item.Value.GetValue(), nil - } - } - - return 0, api.ErrDataNotAvailable -} - -// return current values of a defined measurementType, commodityType and scopeType -// -// if nothing is found, it will return an error -func (m *Measurement) GetValuesForTypeCommodityScope(measurement model.MeasurementTypeType, commodity model.CommodityTypeType, scope model.ScopeTypeType) ([]model.MeasurementDataType, error) { - values, err := m.GetValues() - if err != nil { - return nil, err - } - - var resultSet []model.MeasurementDataType - for _, item := range values { - if item.MeasurementId == nil || item.Value == nil { - continue - } - - desc, err := m.GetDescriptionForMeasurementId(*item.MeasurementId) - if err != nil || - desc.MeasurementType == nil || *desc.MeasurementType != measurement || - desc.CommodityType == nil || *desc.CommodityType != commodity || - desc.ScopeType == nil || *desc.ScopeType != scope { - continue - } - - resultSet = append(resultSet, item) - } - - if len(resultSet) == 0 { - return nil, api.ErrDataNotAvailable - } - - return resultSet, nil -} - -// return measurement constraints -func (m *Measurement) GetConstraints() ([]model.MeasurementConstraintsDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.MeasurementConstraintsListDataType](m.featureRemote, model.FunctionTypeMeasurementConstraintsListData) - if err != nil { - return nil, api.ErrMetadataNotAvailable - } - - return data.MeasurementConstraintsData, nil -} diff --git a/features/measurement_test.go b/features/measurement_test.go deleted file mode 100644 index 03d28a96..00000000 --- a/features/measurement_test.go +++ /dev/null @@ -1,237 +0,0 @@ -package features_test - -import ( - "testing" - "time" - - "github.com/enbility/eebus-go/features" - "github.com/enbility/eebus-go/util" - shipapi "github.com/enbility/ship-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -func TestMeasurementSuite(t *testing.T) { - suite.Run(t, new(MeasurementSuite)) -} - -type MeasurementSuite struct { - suite.Suite - - localEntity spineapi.EntityLocalInterface - remoteEntity spineapi.EntityRemoteInterface - - measurement *features.Measurement - sentMessage []byte -} - -var _ shipapi.ShipConnectionDataWriterInterface = (*MeasurementSuite)(nil) - -func (s *MeasurementSuite) WriteShipMessageWithPayload(message []byte) { - s.sentMessage = message -} - -func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { - s.localEntity, s.remoteEntity = setupFeatures( - s.T(), - s, - []featureFunctions{ - { - featureType: model.FeatureTypeTypeMeasurement, - functions: []model.FunctionType{ - model.FunctionTypeMeasurementDescriptionListData, - model.FunctionTypeMeasurementConstraintsListData, - model.FunctionTypeMeasurementListData, - }, - }, - { - featureType: model.FeatureTypeTypeElectricalConnection, - functions: []model.FunctionType{ - model.FunctionTypeElectricalConnectionDescriptionListData, - model.FunctionTypeElectricalConnectionParameterDescriptionListData, - model.FunctionTypeElectricalConnectionPermittedValueSetListData, - }, - }, - }, - ) - - var err error - s.measurement, err = features.NewMeasurement(s.localEntity, s.remoteEntity) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), s.measurement) -} - -func (s *MeasurementSuite) Test_RequestDescriptions() { - msgCounter, err := s.measurement.RequestDescriptions() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), msgCounter) -} - -func (s *MeasurementSuite) Test_RequestConstraints() { - msgCounter, err := s.measurement.RequestConstraints() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), msgCounter) -} - -func (s *MeasurementSuite) Test_RequestValues() { - counter, err := s.measurement.RequestValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), counter) -} - -func (s *MeasurementSuite) Test_GetValueForMeasurementId() { - measurement := model.MeasurementIdType(0) - - value, err := s.measurement.GetValueForMeasurementId(measurement) - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0.0, value) - - s.addData() - - value, err = s.measurement.GetValueForMeasurementId(measurement) - assert.Nil(s.T(), err) - assert.Equal(s.T(), 9.0, value) - - value, err = s.measurement.GetValueForMeasurementId(model.MeasurementIdType(100)) - assert.NotNil(s.T(), err) - assert.Equal(s.T(), 0.0, value) -} - -func (s *MeasurementSuite) Test_GetValuesForTypeCommodityScope() { - measurement := model.MeasurementTypeTypeCurrent - commodity := model.CommodityTypeTypeElectricity - scope := model.ScopeTypeTypeACCurrent - - data, err := s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) - - measurement = model.MeasurementTypeTypeArea - data, err = s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) -} - -func (s *MeasurementSuite) Test_GetDescriptionsForScope() { - data, err := s.measurement.GetDescriptionsForScope(model.ScopeTypeTypeACCurrent) - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addDescription() - - data, err = s.measurement.GetDescriptionsForScope(model.ScopeTypeTypeACCurrent) - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *MeasurementSuite) Test_GetConstraints() { - data, err := s.measurement.GetConstraints() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addConstraints() - - data, err = s.measurement.GetConstraints() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -func (s *MeasurementSuite) Test_GetValues() { - data, err := s.measurement.GetValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addConstraints() - - s.addDescription() - - data, err = s.measurement.GetValues() - assert.NotNil(s.T(), err) - assert.Nil(s.T(), data) - - s.addData() - - data, err = s.measurement.GetValues() - assert.Nil(s.T(), err) - assert.NotNil(s.T(), data) -} - -// helper - -func (s *MeasurementSuite) addDescription() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.MeasurementDescriptionListDataType{ - MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ - { - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), - Unit: util.Ptr(model.UnitOfMeasurementTypeA), - }, - { - MeasurementId: util.Ptr(model.MeasurementIdType(1)), - MeasurementType: util.Ptr(model.MeasurementTypeTypePercentage), - CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), - ScopeType: util.Ptr(model.ScopeTypeTypeStateOfCharge), - }, - }, - } - rF.UpdateData(model.FunctionTypeMeasurementDescriptionListData, fData, nil, nil) -} - -func (s *MeasurementSuite) addConstraints() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - fData := &model.MeasurementConstraintsListDataType{ - MeasurementConstraintsData: []model.MeasurementConstraintsDataType{ - { - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - ValueRangeMin: model.NewScaledNumberType(2), - ValueRangeMax: model.NewScaledNumberType(16), - ValueStepSize: model.NewScaledNumberType(0.1), - }, - { - MeasurementId: util.Ptr(model.MeasurementIdType(1)), - ValueRangeMin: model.NewScaledNumberType(0), - ValueRangeMax: model.NewScaledNumberType(100), - ValueStepSize: model.NewScaledNumberType(0.1), - }, - }, - } - rF.UpdateData(model.FunctionTypeMeasurementConstraintsListData, fData, nil, nil) -} - -func (s *MeasurementSuite) addData() { - rF := s.remoteEntity.FeatureOfAddress(util.Ptr(model.AddressFeatureType(1))) - - t := time.Now().UTC() - fData := &model.MeasurementListDataType{ - MeasurementData: []model.MeasurementDataType{ - { - MeasurementId: util.Ptr(model.MeasurementIdType(0)), - Value: model.NewScaledNumberType(9), - Timestamp: model.NewAbsoluteOrRelativeTimeTypeFromTime(t), - }, - { - MeasurementId: util.Ptr(model.MeasurementIdType(1)), - Value: model.NewScaledNumberType(9), - Timestamp: model.NewAbsoluteOrRelativeTimeTypeFromTime(t), - }, - }, - } - rF.UpdateData(model.FunctionTypeMeasurementListData, fData, nil, nil) -} diff --git a/features/server/deviceconfiguration.go b/features/server/deviceconfiguration.go new file mode 100644 index 00000000..e30c7b8a --- /dev/null +++ b/features/server/deviceconfiguration.go @@ -0,0 +1,126 @@ +package server + +import ( + "errors" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/spine" +) + +type DeviceConfiguration struct { + *Feature + + *internal.DeviceConfigurationCommon +} + +func NewDeviceConfiguration(localEntity spineapi.EntityLocalInterface) (*DeviceConfiguration, error) { + feature, err := NewFeature(model.FeatureTypeTypeDeviceConfiguration, localEntity) + if err != nil { + return nil, err + } + + dc := &DeviceConfiguration{ + Feature: feature, + DeviceConfigurationCommon: internal.NewLocalDeviceConfiguration(feature.featureLocal), + } + + return dc, nil +} + +var _ api.DeviceConfigurationServerInterface = (*DeviceConfiguration)(nil) + +// Add a new description data set and return the keyId +// +// will return nil if the data set could not be added +func (d *DeviceConfiguration) AddKeyValueDescription( + description model.DeviceConfigurationKeyValueDescriptionDataType, +) *model.DeviceConfigurationKeyIdType { + data, err := spine.LocalFeatureDataCopyOfType[*model.DeviceConfigurationKeyValueDescriptionListDataType](d.featureLocal, model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData) + if err != nil { + data = &model.DeviceConfigurationKeyValueDescriptionListDataType{} + } + + var keyId *model.DeviceConfigurationKeyIdType + + maxId := model.DeviceConfigurationKeyIdType(0) + + for _, item := range data.DeviceConfigurationKeyValueDescriptionData { + if item.KeyId != nil && *item.KeyId >= maxId { + maxId = *item.KeyId + 1 + } + } + + keyId = util.Ptr(maxId) + description.KeyId = keyId + + partial := model.NewFilterTypePartial() + datalist := &model.DeviceConfigurationKeyValueDescriptionListDataType{ + DeviceConfigurationKeyValueDescriptionData: []model.DeviceConfigurationKeyValueDescriptionDataType{description}, + } + + if err := d.featureLocal.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, datalist, partial, nil); err != nil { + return nil + } + + return keyId +} + +// Set or update data set for a keyId +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (d *DeviceConfiguration) UpdateKeyValueDataForKeyId( + data model.DeviceConfigurationKeyValueDataType, + deleteElements *model.DeviceConfigurationKeyValueDataElementsType, + keyId model.DeviceConfigurationKeyIdType, +) (resultErr error) { + return d.UpdateKeyValueDataForFilter(data, deleteElements, model.DeviceConfigurationKeyValueDescriptionDataType{KeyId: &keyId}) +} + +// Set or update data set for a filter +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (d *DeviceConfiguration) UpdateKeyValueDataForFilter( + data model.DeviceConfigurationKeyValueDataType, + deleteElements *model.DeviceConfigurationKeyValueDataElementsType, + filter model.DeviceConfigurationKeyValueDescriptionDataType, +) (resultErr error) { + resultErr = api.ErrDataNotAvailable + + descriptions, err := d.GetKeyValueDescriptionsForFilter(filter) + if err != nil { + return err + } + if descriptions == nil || len(descriptions) != 1 { + return + } + + description := descriptions[0] + data.KeyId = description.KeyId + + datalist := &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{data}, + } + + partial := model.NewFilterTypePartial() + var delete *model.FilterType + if deleteElements != nil { + delete = &model.FilterType{ + DeviceConfigurationKeyValueListDataSelectors: &model.DeviceConfigurationKeyValueListDataSelectorsType{ + KeyId: description.KeyId, + }, + DeviceConfigurationKeyValueDataElements: deleteElements, + } + } + + if err := d.featureLocal.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, datalist, partial, delete); err != nil { + return errors.New(err.String()) + } + + return nil +} diff --git a/features/server/deviceconfiguration_test.go b/features/server/deviceconfiguration_test.go new file mode 100644 index 00000000..f6b874e2 --- /dev/null +++ b/features/server/deviceconfiguration_test.go @@ -0,0 +1,245 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/server" + eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + "github.com/enbility/eebus-go/util" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestDeviceConfigurationSuite(t *testing.T) { + suite.Run(t, new(DeviceConfigurationSuite)) +} + +type DeviceConfigurationSuite struct { + suite.Suite + + sut *server.DeviceConfiguration + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface +} + +func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.sut, err = server.NewDeviceConfiguration(s.localEntity) + assert.Nil(s.T(), err) +} + +func (s *DeviceConfigurationSuite) Test_CheckEventPayloadDataForFilter() { + keyName := model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit + + exists := s.sut.CheckEventPayloadDataForFilter(nil, keyName) + assert.False(s.T(), exists) + + exists = s.sut.CheckEventPayloadDataForFilter(keyName, keyName) + assert.False(s.T(), exists) + + descData := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(keyName), + } + + keyId := s.sut.AddKeyValueDescription(descData) + assert.NotNil(s.T(), keyId) + + exists = s.sut.CheckEventPayloadDataForFilter(nil, descData) + assert.False(s.T(), exists) + + keyData := &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{}, + } + + exists = s.sut.CheckEventPayloadDataForFilter(keyData, descData) + assert.False(s.T(), exists) + + keyData = &model.DeviceConfigurationKeyValueListDataType{ + DeviceConfigurationKeyValueData: []model.DeviceConfigurationKeyValueDataType{ + { + KeyId: keyId, + Value: &model.DeviceConfigurationKeyValueValueType{ + String: util.Ptr(model.DeviceConfigurationKeyValueStringTypeIEC61851), + }, + }, + }, + } + + exists = s.sut.CheckEventPayloadDataForFilter(keyData, descData) + assert.True(s.T(), exists) +} + +func (s *DeviceConfigurationSuite) Test_Description() { + filter1 := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit), + } + + filter2 := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeProductionActivePowerLimit), + } + + data, err := s.sut.GetKeyValueDescriptionsForFilter(filter1) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + data, err = s.sut.GetKeyValueDescriptionsForFilter(filter2) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + desc := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: filter1.KeyName, + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber), + } + keyId := s.sut.AddKeyValueDescription(desc) + assert.NotNil(s.T(), keyId) + + data, err = s.sut.GetKeyValueDescriptionsForFilter(filter1) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + assert.Equal(s.T(), 1, len(data)) + assert.Equal(s.T(), *keyId, *data[0].KeyId) + + result, err := s.sut.GetKeyValueDescriptionFoKeyId(*keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + + data, err = s.sut.GetKeyValueDescriptionsForFilter(filter2) + assert.Nil(s.T(), err) + assert.Nil(s.T(), data) + + desc.KeyName = filter2.KeyName + keyId = s.sut.AddKeyValueDescription(desc) + assert.NotNil(s.T(), keyId) +} + +func (s *DeviceConfigurationSuite) Test_GetKeyValue() { + filter1 := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit), + } + filter2 := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeProductionActivePowerLimit), + } + + data := model.DeviceConfigurationKeyValueDataType{ + IsValueChangeable: util.Ptr(false), + Value: &model.DeviceConfigurationKeyValueValueType{ + ScaledNumber: model.NewScaledNumberType(10), + }, + } + + result, err := s.sut.GetKeyValueDataForFilter(filter1) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + desc := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: filter1.KeyName, + ValueType: util.Ptr(model.DeviceConfigurationKeyValueTypeTypeScaledNumber), + } + keyId := s.sut.AddKeyValueDescription(desc) + assert.NotNil(s.T(), keyId) + + err = s.sut.UpdateKeyValueDataForFilter(data, nil, filter2) + assert.NotNil(s.T(), err) + + err = s.sut.UpdateKeyValueDataForKeyId(data, nil, *keyId) + assert.Nil(s.T(), err) + + result, err = s.sut.GetKeyValueDataForKeyId(*keyId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + assert.Equal(s.T(), *keyId, *result.KeyId) +} + +func (s *DeviceConfigurationSuite) Test_UpdateKeyValueDataForFilter() { + filter := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: util.Ptr(model.DeviceConfigurationKeyNameTypeFailsafeConsumptionActivePowerLimit), + } + + data := model.DeviceConfigurationKeyValueDataType{ + IsValueChangeable: util.Ptr(false), + Value: &model.DeviceConfigurationKeyValueValueType{ + ScaledNumber: model.NewScaledNumberType(10), + }, + } + + err := s.sut.UpdateKeyValueDataForFilter(data, nil, filter) + assert.NotNil(s.T(), err) + + desc := model.DeviceConfigurationKeyValueDescriptionDataType{ + KeyName: filter.KeyName, + } + + keyId := s.sut.AddKeyValueDescription(desc) + assert.NotNil(s.T(), keyId) + + err = s.sut.UpdateKeyValueDataForFilter(data, nil, filter) + assert.Nil(s.T(), err) + + result, err := s.sut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result.KeyId) + assert.Equal(s.T(), *keyId, *result.KeyId) + assert.NotNil(s.T(), result.Value) + assert.NotNil(s.T(), result.Value.ScaledNumber) + assert.Equal(s.T(), 10.0, result.Value.ScaledNumber.GetValue()) + + err = s.sut.UpdateKeyValueDataForFilter(data, nil, filter) + assert.Nil(s.T(), err) + + delete := &model.DeviceConfigurationKeyValueDataElementsType{ + Value: &model.DeviceConfigurationKeyValueValueElementsType{}, + } + data = model.DeviceConfigurationKeyValueDataType{} + err = s.sut.UpdateKeyValueDataForFilter(data, delete, filter) + assert.Nil(s.T(), err) + + result, err = s.sut.GetKeyValueDataForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result.KeyId) + assert.Equal(s.T(), *keyId, *result.KeyId) + assert.Nil(s.T(), result.Value) +} diff --git a/features/server/devicediagnosis.go b/features/server/devicediagnosis.go new file mode 100644 index 00000000..70768c24 --- /dev/null +++ b/features/server/devicediagnosis.go @@ -0,0 +1,35 @@ +package server + +import ( + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type DeviceDiagnosis struct { + *Feature + + *internal.DeviceDiagnosisCommon +} + +func NewDeviceDiagnosis(localEntity spineapi.EntityLocalInterface) (*DeviceDiagnosis, error) { + feature, err := NewFeature(model.FeatureTypeTypeDeviceConfiguration, localEntity) + if err != nil { + return nil, err + } + + dc := &DeviceDiagnosis{ + Feature: feature, + DeviceDiagnosisCommon: internal.NewLocalDeviceDiagnosis(feature.featureLocal), + } + + return dc, nil +} + +var _ api.DeviceDiagnosisServerInterface = (*DeviceDiagnosis)(nil) + +// set the local diagnosis state of the device +func (d *DeviceDiagnosis) SetLocalState(operatingState *model.DeviceDiagnosisStateDataType) { + d.featureLocal.SetData(model.FunctionTypeDeviceDiagnosisStateData, operatingState) +} diff --git a/features/server/devicediagnosis_test.go b/features/server/devicediagnosis_test.go new file mode 100644 index 00000000..9cf3f1bb --- /dev/null +++ b/features/server/devicediagnosis_test.go @@ -0,0 +1,81 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/server" + eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + "github.com/enbility/eebus-go/util" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestDeviceDiagnosisSuite(t *testing.T) { + suite.Run(t, new(DeviceDiagnosisSuite)) +} + +type DeviceDiagnosisSuite struct { + suite.Suite + + sut *server.DeviceDiagnosis + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface +} + +func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.sut, err = server.NewDeviceDiagnosis(s.localEntity) + assert.Nil(s.T(), err) +} + +func (s *DeviceDiagnosisSuite) Test_SetState() { + data := &model.DeviceDiagnosisStateDataType{ + OperatingState: util.Ptr(model.DeviceDiagnosisOperatingStateTypeNormalOperation), + PowerSupplyCondition: util.Ptr(model.PowerSupplyConditionTypeGood), + } + s.sut.SetLocalState(data) +} diff --git a/features/server/electricalconnection.go b/features/server/electricalconnection.go new file mode 100644 index 00000000..0d91f708 --- /dev/null +++ b/features/server/electricalconnection.go @@ -0,0 +1,185 @@ +package server + +import ( + "errors" + + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/spine" +) + +type ElectricalConnection struct { + *Feature + + *internal.ElectricalConnectionCommon +} + +func NewElectricalConnection(localEntity spineapi.EntityLocalInterface) (*ElectricalConnection, error) { + feature, err := NewFeature(model.FeatureTypeTypeElectricalConnection, localEntity) + if err != nil { + return nil, err + } + + ec := &ElectricalConnection{ + Feature: feature, + ElectricalConnectionCommon: internal.NewLocalElectricalConnection(feature.featureLocal), + } + + return ec, nil +} + +// Add a new description data set +// +// NOTE: the electricalConnectionId has to be provided +// +// will return nil if the data set could not be added +func (e *ElectricalConnection) AddDescription( + description model.ElectricalConnectionDescriptionDataType, +) error { + if description.ElectricalConnectionId == nil { + return errors.New("missing id data") + } + + partial := model.NewFilterTypePartial() + datalist := &model.ElectricalConnectionDescriptionListDataType{ + ElectricalConnectionDescriptionData: []model.ElectricalConnectionDescriptionDataType{description}, + } + + if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionDescriptionListData, datalist, partial, nil); err != nil { + return errors.New(err.String()) + } + + return nil +} + +// Add a new parameter description data sett and return the parameterId +// +// NOTE: the electricalConnectionId has to be provided, parameterId may not be provided +// +// will return nil if the data set could not be added +func (e *ElectricalConnection) AddParameterDescription( + description model.ElectricalConnectionParameterDescriptionDataType, +) *model.ElectricalConnectionParameterIdType { + if description.ElectricalConnectionId == nil || description.ParameterId != nil { + return nil + } + + filter := model.ElectricalConnectionParameterDescriptionDataType{ + ElectricalConnectionId: description.ElectricalConnectionId, + } + data, _ := e.GetParameterDescriptionsForFilter(filter) + + maxId := model.ElectricalConnectionParameterIdType(0) + + for _, item := range data { + if item.ParameterId != nil && *item.ParameterId >= maxId { + maxId = *item.ParameterId + 1 + } + } + + parameterId := util.Ptr(maxId) + description.ParameterId = parameterId + + partial := model.NewFilterTypePartial() + datalist := &model.ElectricalConnectionParameterDescriptionListDataType{ + ElectricalConnectionParameterDescriptionData: []model.ElectricalConnectionParameterDescriptionDataType{description}, + } + + if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionParameterDescriptionListData, datalist, partial, nil); err != nil { + return nil + } + + return parameterId +} + +// Add a new characteristic data set +// +// Note: ElectricalConnectionId and ParameterId must be set, CharacteristicId will be set automatically +// +// Will return an error if the data set could not be added +func (e *ElectricalConnection) AddCharacteristic(data model.ElectricalConnectionCharacteristicDataType) (*model.ElectricalConnectionCharacteristicIdType, error) { + if data.ElectricalConnectionId == nil || + data.ParameterId == nil { + return nil, errors.New("missing id data") + } + if data.CharacteristicId != nil { + return nil, errors.New("characteristic id must not be set") + } + + maxId := model.ElectricalConnectionCharacteristicIdType(0) + + listData, err := spine.LocalFeatureDataCopyOfType[*model.ElectricalConnectionCharacteristicListDataType](e.featureLocal, model.FunctionTypeElectricalConnectionCharacteristicListData) + if err != nil { + listData = &model.ElectricalConnectionCharacteristicListDataType{} + } + + for _, item := range listData.ElectricalConnectionCharacteristicData { + if item.CharacteristicId != nil && *item.CharacteristicId >= maxId { + maxId = *item.CharacteristicId + 1 + } + } + + charId := util.Ptr(maxId) + data.CharacteristicId = charId + + datalist := &model.ElectricalConnectionCharacteristicListDataType{ + ElectricalConnectionCharacteristicData: []model.ElectricalConnectionCharacteristicDataType{data}, + } + + partial := model.NewFilterTypePartial() + if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, datalist, partial, nil); err != nil { + return nil, errors.New(err.String()) + } + + return charId, nil +} + +// Update data set for a filter +// Elements provided in deleteElements will be removed from the data set before the update +// +// // ElectricalConnectionId, ParameterId and CharacteristicId must be set +// +// Will return an error if the data set could not be updated +func (e *ElectricalConnection) UpdateCharacteristic( + data model.ElectricalConnectionCharacteristicDataType, + deleteElements *model.ElectricalConnectionCharacteristicDataElementsType, +) error { + if data.CharacteristicId == nil || + data.ElectricalConnectionId == nil || + data.ParameterId == nil { + return errors.New("missing id data") + } + + filter := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: data.ElectricalConnectionId, + ParameterId: data.ParameterId, + CharacteristicId: data.CharacteristicId, + } + chars, err := e.GetCharacteristicsForFilter(filter) + if err != nil || chars == nil || len(chars) != 1 { + return errors.New("no matching element found") + } + + partial := model.NewFilterTypePartial() + var delete *model.FilterType + if deleteElements != nil { + delete = &model.FilterType{ + ElectricalConnectionCharacteristicListDataSelectors: &model.ElectricalConnectionCharacteristicListDataSelectorsType{ + CharacteristicId: data.CharacteristicId, + }, + ElectricalConnectionCharacteristicDataElements: deleteElements, + } + } + + datalist := &model.ElectricalConnectionCharacteristicListDataType{ + ElectricalConnectionCharacteristicData: []model.ElectricalConnectionCharacteristicDataType{data}, + } + + if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, datalist, partial, delete); err != nil { + return errors.New(err.String()) + } + + return nil +} diff --git a/features/server/electricalconnection_test.go b/features/server/electricalconnection_test.go new file mode 100644 index 00000000..b690714f --- /dev/null +++ b/features/server/electricalconnection_test.go @@ -0,0 +1,253 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/server" + eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + "github.com/enbility/eebus-go/util" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestElectricalConnectionSuite(t *testing.T) { + suite.Run(t, new(ElectricalConnectionSuite)) +} + +type ElectricalConnectionSuite struct { + suite.Suite + + sut *server.ElectricalConnection + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface +} + +func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.sut, err = server.NewElectricalConnection(s.localEntity) + assert.Nil(s.T(), err) +} + +func (s *ElectricalConnectionSuite) Test_Description() { + filter := model.ElectricalConnectionDescriptionDataType{} + + data, err := s.sut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + desc := model.ElectricalConnectionDescriptionDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + PowerSupplyType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeAc), + AcConnectedPhases: util.Ptr(uint(3)), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + err = s.sut.AddDescription(desc) + assert.Nil(s.T(), err) + + filter.ElectricalConnectionId = desc.ElectricalConnectionId + data, err = s.sut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + desc = model.ElectricalConnectionDescriptionDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(1)), + PowerSupplyType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeDc), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + err = s.sut.AddDescription(desc) + assert.Nil(s.T(), err) + + desc = model.ElectricalConnectionDescriptionDataType{ + PowerSupplyType: util.Ptr(model.ElectricalConnectionVoltageTypeTypeDc), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + err = s.sut.AddDescription(desc) + assert.NotNil(s.T(), err) + + filter.ElectricalConnectionId = desc.ElectricalConnectionId + data, err = s.sut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_ParameterDescription() { + filter := model.ElectricalConnectionParameterDescriptionDataType{} + + data, err := s.sut.GetParameterDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + desc := model.ElectricalConnectionParameterDescriptionDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + pId := s.sut.AddParameterDescription(desc) + assert.NotNil(s.T(), pId) + + filter.ElectricalConnectionId = desc.ElectricalConnectionId + data, err = s.sut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + desc = model.ElectricalConnectionParameterDescriptionDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + pId = s.sut.AddParameterDescription(desc) + assert.NotNil(s.T(), pId) + + desc = model.ElectricalConnectionParameterDescriptionDataType{ + ScopeType: util.Ptr(model.ScopeTypeTypeACPowerTotal), + } + + pId = s.sut.AddParameterDescription(desc) + assert.Nil(s.T(), pId) + + filter.ElectricalConnectionId = desc.ElectricalConnectionId + data, err = s.sut.GetParameterDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) +} + +func (s *ElectricalConnectionSuite) Test_GetCharacteristicsForFilter() { + filter := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax), + } + + result, err := s.sut.GetCharacteristicsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + charData := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicContext: filter.CharacteristicContext, + CharacteristicType: filter.CharacteristicType, + Value: model.NewScaledNumberType(10), + } + charId, err := s.sut.AddCharacteristic(charData) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), charId) + + result, err = s.sut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + + charData.CharacteristicType = util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeContractualConsumptionNominalMax) + charId, err = s.sut.AddCharacteristic(charData) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), charId) + + result, err = s.sut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + + charData.CharacteristicId = util.Ptr(model.ElectricalConnectionCharacteristicIdType(100)) + charId, err = s.sut.AddCharacteristic(charData) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), charId) + + charData.ElectricalConnectionId = nil + charId, err = s.sut.AddCharacteristic(charData) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), charId) +} + +func (s *ElectricalConnectionSuite) Test_UpdateCharacteristic() { + charData := model.ElectricalConnectionCharacteristicDataType{ + ElectricalConnectionId: util.Ptr(model.ElectricalConnectionIdType(0)), + ParameterId: util.Ptr(model.ElectricalConnectionParameterIdType(0)), + CharacteristicContext: util.Ptr(model.ElectricalConnectionCharacteristicContextTypeEntity), + CharacteristicType: util.Ptr(model.ElectricalConnectionCharacteristicTypeTypeApparentPowerConsumptionNominalMax), + Value: model.NewScaledNumberType(10), + } + + err := s.sut.UpdateCharacteristic(charData, nil) + assert.NotNil(s.T(), err) + + charId, err := s.sut.AddCharacteristic(charData) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), charId) + + filter := model.ElectricalConnectionCharacteristicDataType{ + CharacteristicId: charId, + } + data, err := s.sut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + assert.Equal(s.T(), 1, len(data)) + assert.NotNil(s.T(), data[0].Value) + assert.Equal(s.T(), 10.0, data[0].Value.GetValue()) + + charData.CharacteristicId = util.Ptr(model.ElectricalConnectionCharacteristicIdType(100)) + charData.Value = model.NewScaledNumberType(20) + err = s.sut.UpdateCharacteristic(charData, nil) + assert.NotNil(s.T(), err) + + charData.CharacteristicId = charId + err = s.sut.UpdateCharacteristic(charData, nil) + assert.Nil(s.T(), err) + + delete := &model.ElectricalConnectionCharacteristicDataElementsType{ + Value: &model.ScaledNumberElementsType{}, + } + charData.Value = nil + err = s.sut.UpdateCharacteristic(charData, delete) + assert.Nil(s.T(), err) + + data, err = s.sut.GetCharacteristicsForFilter(filter) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + assert.Equal(s.T(), 1, len(data)) + assert.Nil(s.T(), data[0].Value) +} diff --git a/features/server/feature.go b/features/server/feature.go new file mode 100644 index 00000000..f50ffff1 --- /dev/null +++ b/features/server/feature.go @@ -0,0 +1,43 @@ +package server + +import ( + "errors" + + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type Feature struct { + featureType model.FeatureTypeType + + localRole model.RoleType + + spineLocalDevice spineapi.DeviceLocalInterface + localEntity spineapi.EntityLocalInterface + + featureLocal spineapi.FeatureLocalInterface +} + +// var _ api.FeatureServerInterface = (*Feature)(nil) + +func NewFeature( + featureType model.FeatureTypeType, + localEntity spineapi.EntityLocalInterface) (*Feature, error) { + if localEntity == nil { + return nil, errors.New("local entity is nil") + } + + f := &Feature{ + featureType: featureType, + localRole: model.RoleTypeServer, + spineLocalDevice: localEntity.Device(), + localEntity: localEntity, + } + + f.featureLocal = f.localEntity.FeatureOfTypeAndRole(f.featureType, f.localRole) + if f.featureLocal == nil { + return nil, errors.New("local feature not found") + } + + return f, nil +} diff --git a/features/server/feature_test.go b/features/server/feature_test.go new file mode 100644 index 00000000..898e68d7 --- /dev/null +++ b/features/server/feature_test.go @@ -0,0 +1,82 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + features "github.com/enbility/eebus-go/features/server" + "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + shipapi "github.com/enbility/ship-go/api" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestFeatureSuite(t *testing.T) { + suite.Run(t, new(FeatureSuite)) +} + +type FeatureSuite struct { + suite.Suite + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + + testFeature *features.Feature + sentMessage []byte +} + +var _ shipapi.ShipConnectionDataWriterInterface = (*FeatureSuite)(nil) + +func (s *FeatureSuite) WriteShipMessageWithPayload(message []byte) { + s.sentMessage = message +} + +func (s *FeatureSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := mocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.testFeature, err = features.NewFeature(model.FeatureTypeTypeLoadControl, s.localEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), s.testFeature) +} + +func (s *FeatureSuite) Test_NewFeature() { + newFeature, err := features.NewFeature(model.FeatureTypeTypeBill, nil) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), newFeature) + + newFeature, err = features.NewFeature(model.FeatureTypeTypeBill, s.localEntity) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), newFeature) + + newFeature, err = features.NewFeature(model.FeatureTypeTypeDeviceConfiguration, s.localEntity) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), newFeature) +} diff --git a/features/server/helper_test.go b/features/server/helper_test.go new file mode 100644 index 00000000..58c04157 --- /dev/null +++ b/features/server/helper_test.go @@ -0,0 +1,174 @@ +package server_test + +import ( + "fmt" + "testing" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/util" + shipmocks "github.com/enbility/ship-go/mocks" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/spine" + "github.com/stretchr/testify/mock" +) + +const remoteSki string = "testremoteski" + +func setupFeatures( + eebusService api.ServiceInterface, t *testing.T) ( + spineapi.DeviceRemoteInterface, + []spineapi.EntityRemoteInterface) { + localDevice := eebusService.LocalDevice() + localEntity := localDevice.EntityForType(model.EntityTypeTypeCEM) + + f := spine.NewFeatureLocal(1, localEntity, model.FeatureTypeTypeLoadControl, model.RoleTypeClient) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(2, localEntity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeClient) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(3, localEntity, model.FeatureTypeTypeMeasurement, model.RoleTypeClient) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(4, localEntity, model.FeatureTypeTypeDeviceClassification, model.RoleTypeClient) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(5, localEntity, model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeClient) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(6, localEntity, model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + f.AddFunctionType(model.FunctionTypeLoadControlLimitDescriptionListData, true, false) + f.AddFunctionType(model.FunctionTypeLoadControlLimitListData, true, true) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(7, localEntity, model.FeatureTypeTypeElectricalConnection, model.RoleTypeServer) + f.AddFunctionType(model.FunctionTypeElectricalConnectionParameterDescriptionListData, true, false) + f.AddFunctionType(model.FunctionTypeElectricalConnectionPermittedValueSetListData, true, false) + f.AddFunctionType(model.FunctionTypeElectricalConnectionCharacteristicListData, true, true) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(8, localEntity, model.FeatureTypeTypeDeviceConfiguration, model.RoleTypeServer) + f.AddFunctionType(model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, true, false) + f.AddFunctionType(model.FunctionTypeDeviceConfigurationKeyValueListData, true, true) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(9, localEntity, model.FeatureTypeTypeDeviceClassification, model.RoleTypeServer) + f.AddFunctionType(model.FunctionTypeDeviceClassificationManufacturerData, true, false) + f.AddFunctionType(model.FunctionTypeDeviceClassificationUserData, true, true) + localEntity.AddFeature(f) + f = spine.NewFeatureLocal(10, localEntity, model.FeatureTypeTypeMeasurement, model.RoleTypeServer) + f.AddFunctionType(model.FunctionTypeMeasurementDescriptionListData, true, false) + f.AddFunctionType(model.FunctionTypeMeasurementListData, true, false) + localEntity.AddFeature(f) + + writeHandler := shipmocks.NewShipConnectionDataWriterInterface(t) + writeHandler.EXPECT().WriteShipMessageWithPayload(mock.Anything).Return().Maybe() + sender := spine.NewSender(writeHandler) + remoteDevice := spine.NewDeviceRemote(localDevice, remoteSki, sender) + + var remoteFeatures = []struct { + featureType model.FeatureTypeType + role model.RoleType + supportedFcts []model.FunctionType + }{ + {model.FeatureTypeTypeLoadControl, + model.RoleTypeServer, + []model.FunctionType{ + model.FunctionTypeLoadControlLimitDescriptionListData, + model.FunctionTypeLoadControlLimitConstraintsListData, + model.FunctionTypeLoadControlLimitListData, + }, + }, + {model.FeatureTypeTypeElectricalConnection, + model.RoleTypeServer, + []model.FunctionType{ + model.FunctionTypeElectricalConnectionParameterDescriptionListData, + model.FunctionTypeElectricalConnectionPermittedValueSetListData, + }, + }, + {model.FeatureTypeTypeMeasurement, + model.RoleTypeServer, + []model.FunctionType{ + model.FunctionTypeMeasurementDescriptionListData, + model.FunctionTypeMeasurementListData, + }, + }, + {model.FeatureTypeTypeDeviceClassification, + model.RoleTypeServer, + []model.FunctionType{ + model.FunctionTypeDeviceClassificationManufacturerData, + model.FunctionTypeDeviceClassificationUserData, + }, + }, + {model.FeatureTypeTypeDeviceConfiguration, + model.RoleTypeServer, + []model.FunctionType{ + model.FunctionTypeDeviceConfigurationKeyValueDescriptionListData, + model.FunctionTypeDeviceConfigurationKeyValueListData, + }, + }, + } + + remoteDeviceName := "remote" + + var featureInformations []model.NodeManagementDetailedDiscoveryFeatureInformationType + for index, feature := range remoteFeatures { + supportedFcts := []model.FunctionPropertyType{} + for _, fct := range feature.supportedFcts { + supportedFct := model.FunctionPropertyType{ + Function: util.Ptr(fct), + PossibleOperations: &model.PossibleOperationsType{ + Read: &model.PossibleOperationsReadType{}, + }, + } + supportedFcts = append(supportedFcts, supportedFct) + } + + featureInformation := model.NodeManagementDetailedDiscoveryFeatureInformationType{ + Description: &model.NetworkManagementFeatureDescriptionDataType{ + FeatureAddress: &model.FeatureAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + Entity: []model.AddressEntityType{1, 1}, + Feature: util.Ptr(model.AddressFeatureType(index)), + }, + FeatureType: util.Ptr(feature.featureType), + Role: util.Ptr(feature.role), + SupportedFunction: supportedFcts, + }, + } + featureInformations = append(featureInformations, featureInformation) + } + + detailedData := &model.NodeManagementDetailedDiscoveryDataType{ + DeviceInformation: &model.NodeManagementDetailedDiscoveryDeviceInformationType{ + Description: &model.NetworkManagementDeviceDescriptionDataType{ + DeviceAddress: &model.DeviceAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + }, + }, + }, + EntityInformation: []model.NodeManagementDetailedDiscoveryEntityInformationType{ + { + Description: &model.NetworkManagementEntityDescriptionDataType{ + EntityAddress: &model.EntityAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + Entity: []model.AddressEntityType{1}, + }, + EntityType: util.Ptr(model.EntityTypeTypeEVSE), + }, + }, + { + Description: &model.NetworkManagementEntityDescriptionDataType{ + EntityAddress: &model.EntityAddressType{ + Device: util.Ptr(model.AddressDeviceType(remoteDeviceName)), + Entity: []model.AddressEntityType{1, 1}, + }, + EntityType: util.Ptr(model.EntityTypeTypeEV), + }, + }, + }, + FeatureInformation: featureInformations, + } + + entities, err := remoteDevice.AddEntityAndFeatures(true, detailedData) + if err != nil { + fmt.Println(err) + } + + localDevice.AddRemoteDeviceForSki(remoteSki, remoteDevice) + + return remoteDevice, entities +} diff --git a/features/server/loadcontrol.go b/features/server/loadcontrol.go new file mode 100644 index 00000000..39e80591 --- /dev/null +++ b/features/server/loadcontrol.go @@ -0,0 +1,124 @@ +package server + +import ( + "errors" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type LoadControl struct { + *Feature + + *internal.LoadControlCommon +} + +func NewLoadControl(localEntity spineapi.EntityLocalInterface) (*LoadControl, error) { + feature, err := NewFeature(model.FeatureTypeTypeLoadControl, localEntity) + if err != nil { + return nil, err + } + + lc := &LoadControl{ + Feature: feature, + LoadControlCommon: internal.NewLocalLoadControl(feature.featureLocal), + } + + return lc, nil +} + +// Add a new description data set and return the limitId +// +// NOTE: the limitId may not be provided +// +// will return nil if the data set could not be added +func (l *LoadControl) AddLimitDescription( + description model.LoadControlLimitDescriptionDataType, +) *model.LoadControlLimitIdType { + if description.LimitId != nil { + return nil + } + + data, err := l.GetLimitDescriptionsForFilter(model.LoadControlLimitDescriptionDataType{}) + if err != nil { + data = []model.LoadControlLimitDescriptionDataType{} + } + + maxId := model.LoadControlLimitIdType(0) + + for _, item := range data { + if item.LimitId != nil && *item.LimitId >= maxId { + maxId = *item.LimitId + 1 + } + } + + limitId := util.Ptr(maxId) + description.LimitId = limitId + + partial := model.NewFilterTypePartial() + datalist := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{description}, + } + + if err := l.featureLocal.UpdateData(model.FunctionTypeLoadControlLimitDescriptionListData, datalist, partial, nil); err != nil { + return nil + } + + return limitId +} + +// Set or update data set for a limitId +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (l *LoadControl) UpdateLimitDataForId( + data model.LoadControlLimitDataType, + deleteElements *model.LoadControlLimitDataElementsType, + limitId model.LoadControlLimitIdType, +) (resultErr error) { + return l.UpdateLimitDataForFilter(data, deleteElements, model.LoadControlLimitDescriptionDataType{LimitId: &limitId}) +} + +// Set or update data set for a filter +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (l *LoadControl) UpdateLimitDataForFilter( + data model.LoadControlLimitDataType, + deleteElements *model.LoadControlLimitDataElementsType, + filter model.LoadControlLimitDescriptionDataType, +) (resultErr error) { + resultErr = api.ErrDataNotAvailable + + descriptions, err := l.GetLimitDescriptionsForFilter(filter) + if err != nil || descriptions == nil || len(descriptions) != 1 { + return + } + + description := descriptions[0] + data.LimitId = description.LimitId + + datalist := &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{data}, + } + + partial := model.NewFilterTypePartial() + var delete *model.FilterType + if deleteElements != nil { + delete = &model.FilterType{ + LoadControlLimitListDataSelectors: &model.LoadControlLimitListDataSelectorsType{ + LimitId: description.LimitId, + }, + LoadControlLimitDataElements: deleteElements, + } + } + + if err := l.featureLocal.UpdateData(model.FunctionTypeLoadControlLimitListData, datalist, partial, delete); err != nil { + return errors.New(err.String()) + } + + return nil +} diff --git a/features/server/loadcontrol_test.go b/features/server/loadcontrol_test.go new file mode 100644 index 00000000..ea8fe26e --- /dev/null +++ b/features/server/loadcontrol_test.go @@ -0,0 +1,280 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/server" + eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + "github.com/enbility/eebus-go/util" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestLoadControlSuite(t *testing.T) { + suite.Run(t, new(LoadControlSuite)) +} + +type LoadControlSuite struct { + suite.Suite + + sut *server.LoadControl + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface +} + +func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.sut, err = server.NewLoadControl(s.localEntity) + assert.Nil(s.T(), err) +} + +func (s *LoadControlSuite) Test_CheckEventPayloadDataForFilter() { + filter := model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeMaxValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + ScopeType: util.Ptr(model.ScopeTypeTypeSelfConsumption), + } + + exists := s.sut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + exists = s.sut.CheckEventPayloadDataForFilter(s.mockRemoteEntity, filter) + assert.False(s.T(), exists) + + descData := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitCategory: filter.LimitCategory, + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + LimitType: filter.LimitType, + ScopeType: filter.ScopeType, + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + LimitCategory: filter.LimitCategory, + MeasurementId: util.Ptr(model.MeasurementIdType(1)), + LimitType: filter.LimitType, + ScopeType: filter.ScopeType, + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + LimitCategory: filter.LimitCategory, + MeasurementId: util.Ptr(model.MeasurementIdType(2)), + LimitType: filter.LimitType, + ScopeType: filter.ScopeType, + }, + }, + } + + entity := s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + feature := entity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + feature.SetData(model.FunctionTypeLoadControlLimitDescriptionListData, descData) + + exists = s.sut.CheckEventPayloadDataForFilter(nil, filter) + assert.False(s.T(), exists) + + limitData := &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{}, + } + + exists = s.sut.CheckEventPayloadDataForFilter(limitData, filter) + assert.False(s.T(), exists) + + limitData = &model.LoadControlLimitListDataType{ + LoadControlLimitData: []model.LoadControlLimitDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + Value: model.NewScaledNumberType(16), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(1)), + Value: model.NewScaledNumberType(16), + }, + { + LimitId: util.Ptr(model.LoadControlLimitIdType(2)), + }, + }, + } + + exists = s.sut.CheckEventPayloadDataForFilter(limitData, filter) + assert.True(s.T(), exists) +} + +func (s *LoadControlSuite) Test_Description() { + data, err := s.sut.GetLimitDescriptionForId(model.LoadControlLimitIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + desc := model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + } + limitId1 := s.sut.AddLimitDescription(desc) + assert.NotNil(s.T(), limitId1) + + data, err = s.sut.GetLimitDescriptionForId(*limitId1) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + desc = model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeProduce), + } + + limitId2 := s.sut.AddLimitDescription(desc) + assert.NotNil(s.T(), limitId2) + + limitData, err := s.sut.GetLimitDescriptionForId(*limitId2) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), limitData) +} + +func (s *LoadControlSuite) Test_GetDescriptionsForFilter() { + filter := model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + } + + data, err := s.sut.GetLimitDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + feature := s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeLoadControl, model.RoleTypeServer) + + desc := &model.LoadControlLimitDescriptionListDataType{ + LoadControlLimitDescriptionData: []model.LoadControlLimitDescriptionDataType{ + { + LimitId: util.Ptr(model.LoadControlLimitIdType(0)), + LimitType: filter.LimitType, + LimitCategory: filter.LimitCategory, + LimitDirection: filter.LimitDirection, + ScopeType: filter.ScopeType, + }, + }, + } + feature.SetData(model.FunctionTypeLoadControlLimitDescriptionListData, desc) + + data, err = s.sut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 1, len(data)) + assert.NotNil(s.T(), data[0].LimitId) + + filter = model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeProduce), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + } + + data, err = s.sut.GetLimitDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) +} + +func (s *LoadControlSuite) Test_GetLimitData() { + filter := model.LoadControlLimitDescriptionDataType{ + LimitType: util.Ptr(model.LoadControlLimitTypeTypeSignDependentAbsValueLimit), + LimitCategory: util.Ptr(model.LoadControlCategoryTypeObligation), + LimitDirection: util.Ptr(model.EnergyDirectionTypeConsume), + ScopeType: util.Ptr(model.ScopeTypeTypeActivePowerLimit), + } + + data := model.LoadControlLimitDataType{} + err := s.sut.UpdateLimitDataForFilter(data, nil, filter) + assert.NotNil(s.T(), err) + + data = model.LoadControlLimitDataType{ + LimitId: util.Ptr(model.LoadControlLimitIdType(100)), + } + err = s.sut.UpdateLimitDataForFilter(data, nil, filter) + assert.NotNil(s.T(), err) + + limitId := s.sut.AddLimitDescription(filter) + assert.NotNil(s.T(), limitId) + + descData, err := s.sut.GetLimitDescriptionForId(*limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), descData) + + result, err := s.sut.GetLimitDataForId(*limitId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + data = model.LoadControlLimitDataType{ + LimitId: limitId, + Value: model.NewScaledNumberType(16), + TimePeriod: model.NewTimePeriodTypeWithRelativeEndTime(time.Minute * 2), + } + err = s.sut.UpdateLimitDataForFilter(data, nil, filter) + assert.Nil(s.T(), err) + + result, err = s.sut.GetLimitDataForId(*limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + + result, err = s.sut.GetLimitDataForId(model.LoadControlLimitIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + data = model.LoadControlLimitDataType{} + delete := &model.LoadControlLimitDataElementsType{ + TimePeriod: &model.TimePeriodElementsType{}, + } + err = s.sut.UpdateLimitDataForId(data, delete, *limitId) + assert.Nil(s.T(), err) + + result, err = s.sut.GetLimitDataForId(*limitId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + assert.Nil(s.T(), result.TimePeriod) +} diff --git a/features/server/measurement.go b/features/server/measurement.go new file mode 100644 index 00000000..992172db --- /dev/null +++ b/features/server/measurement.go @@ -0,0 +1,126 @@ +package server + +import ( + "errors" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/internal" + "github.com/enbility/eebus-go/util" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/model" +) + +type Measurement struct { + *Feature + + *internal.MeasurementCommon +} + +func NewMeasurement(localEntity spineapi.EntityLocalInterface) (*Measurement, error) { + feature, err := NewFeature(model.FeatureTypeTypeMeasurement, localEntity) + if err != nil { + return nil, err + } + + m := &Measurement{ + Feature: feature, + MeasurementCommon: internal.NewLocalMeasurement(feature.featureLocal), + } + + return m, nil +} + +var _ api.MeasurementServerInterface = (*Measurement)(nil) + +// Add a new parameter description data sett and return the measurementId +// +// NOTE: the measurementId may not be provided +// +// will return nil if the data set could not be added +func (m *Measurement) AddDescription( + description model.MeasurementDescriptionDataType, +) *model.MeasurementIdType { + if description.MeasurementId != nil { + return nil + } + + data, err := m.GetDescriptionsForFilter(model.MeasurementDescriptionDataType{}) + if err != nil { + data = []model.MeasurementDescriptionDataType{} + } + + maxId := model.MeasurementIdType(0) + + for _, item := range data { + if item.MeasurementId != nil && *item.MeasurementId >= maxId { + maxId = *item.MeasurementId + 1 + } + } + + measurementId := util.Ptr(maxId) + description.MeasurementId = measurementId + + partial := model.NewFilterTypePartial() + datalist := &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{description}, + } + + if err := m.featureLocal.UpdateData(model.FunctionTypeMeasurementDescriptionListData, datalist, partial, nil); err != nil { + return nil + } + + return measurementId +} + +// Set or update data set for a measurementId +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (m *Measurement) UpdateDataForId( + data model.MeasurementDataType, + deleteElements *model.MeasurementDataElementsType, + measurementId model.MeasurementIdType, +) (resultErr error) { + return m.UpdateDataForFilter(data, deleteElements, model.MeasurementDescriptionDataType{MeasurementId: &measurementId}) +} + +// Set or update data set for a filter +// Elements provided in deleteElements will be removed from the data set before the update +// +// Will return an error if the data set could not be updated +func (m *Measurement) UpdateDataForFilter( + data model.MeasurementDataType, + deleteElements *model.MeasurementDataElementsType, + filter model.MeasurementDescriptionDataType, +) (resultErr error) { + resultErr = api.ErrDataNotAvailable + + descriptions, err := m.GetDescriptionsForFilter(filter) + if err != nil || descriptions == nil || len(descriptions) != 1 { + return + } + + description := descriptions[0] + data.MeasurementId = description.MeasurementId + + datalist := &model.MeasurementListDataType{ + MeasurementData: []model.MeasurementDataType{data}, + } + + partial := model.NewFilterTypePartial() + var delete *model.FilterType + if deleteElements != nil { + delete = &model.FilterType{ + MeasurementListDataSelectors: &model.MeasurementListDataSelectorsType{ + MeasurementId: description.MeasurementId, + }, + MeasurementDataElements: deleteElements, + } + } + + if err := m.featureLocal.UpdateData(model.FunctionTypeMeasurementListData, datalist, partial, delete); err != nil { + return errors.New(err.String()) + } + + return nil +} diff --git a/features/server/measurement_test.go b/features/server/measurement_test.go new file mode 100644 index 00000000..857d3a85 --- /dev/null +++ b/features/server/measurement_test.go @@ -0,0 +1,203 @@ +package server_test + +import ( + "testing" + "time" + + "github.com/enbility/eebus-go/api" + "github.com/enbility/eebus-go/features/server" + eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/service" + "github.com/enbility/eebus-go/util" + "github.com/enbility/ship-go/cert" + spineapi "github.com/enbility/spine-go/api" + "github.com/enbility/spine-go/mocks" + "github.com/enbility/spine-go/model" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" + "github.com/stretchr/testify/suite" +) + +func TestMeasurementSuite(t *testing.T) { + suite.Run(t, new(MeasurementSuite)) +} + +type MeasurementSuite struct { + suite.Suite + + sut *server.Measurement + + service api.ServiceInterface + + localEntity spineapi.EntityLocalInterface + + remoteDevice spineapi.DeviceRemoteInterface + remoteEntity spineapi.EntityRemoteInterface + mockRemoteEntity *mocks.EntityRemoteInterface +} + +func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { + cert, _ := cert.CreateCertificate("test", "test", "DE", "test") + configuration, _ := api.NewConfiguration( + "test", "test", "test", "test", + model.DeviceTypeTypeEnergyManagementSystem, + []model.EntityTypeType{model.EntityTypeTypeCEM}, + 9999, cert, 230.0, time.Second*4) + + serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() + + s.service = service.NewService(configuration, serviceHandler) + _ = s.service.Setup() + s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) + + mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() + mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() + s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() + s.mockRemoteEntity.EXPECT().EntityType().Return(mock.Anything).Maybe() + entityAddress := &model.EntityAddressType{} + s.mockRemoteEntity.EXPECT().Address().Return(entityAddress).Maybe() + mockRemoteFeature.EXPECT().DataCopy(mock.Anything).Return(mock.Anything).Maybe() + + var entities []spineapi.EntityRemoteInterface + + s.remoteDevice, entities = setupFeatures(s.service, s.T()) + s.remoteEntity = entities[1] + + var err error + s.sut, err = server.NewMeasurement(s.localEntity) + assert.Nil(s.T(), err) +} + +func (s *MeasurementSuite) Test_Description() { + data, err := s.sut.GetDescriptionForId(model.MeasurementIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), data) + + desc := model.MeasurementDescriptionDataType{ + MeasurementType: util.Ptr(model.MeasurementTypeTypePower), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + Unit: util.Ptr(model.UnitOfMeasurementTypeW), + ScopeType: util.Ptr(model.ScopeTypeTypeACPower), + } + measId1 := s.sut.AddDescription(desc) + assert.NotNil(s.T(), measId1) + + data, err = s.sut.GetDescriptionForId(*measId1) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), data) + + desc = model.MeasurementDescriptionDataType{ + MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + Unit: util.Ptr(model.UnitOfMeasurementTypeA), + ScopeType: util.Ptr(model.ScopeTypeTypeACCurrentA), + } + + measId2 := s.sut.AddDescription(desc) + assert.NotNil(s.T(), measId2) + + limitData, err := s.sut.GetDescriptionForId(*measId2) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), limitData) +} + +func (s *MeasurementSuite) Test_GetDescriptionsForFilter() { + filter := model.MeasurementDescriptionDataType{ + MeasurementType: util.Ptr(model.MeasurementTypeTypeEnergy), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + ScopeType: util.Ptr(model.ScopeTypeTypeStateOfCharge), + } + + data, err := s.sut.GetDescriptionsForFilter(filter) + assert.NotNil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) + + feature := s.localEntity.FeatureOfTypeAndRole(model.FeatureTypeTypeMeasurement, model.RoleTypeServer) + + desc := &model.MeasurementDescriptionListDataType{ + MeasurementDescriptionData: []model.MeasurementDescriptionDataType{ + { + MeasurementId: util.Ptr(model.MeasurementIdType(0)), + MeasurementType: filter.MeasurementType, + ScopeType: filter.ScopeType, + }, + }, + } + feature.SetData(model.FunctionTypeMeasurementDescriptionListData, desc) + + data, err = s.sut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 1, len(data)) + assert.NotNil(s.T(), data[0].MeasurementId) + + filter = model.MeasurementDescriptionDataType{ + MeasurementType: util.Ptr(model.MeasurementTypeTypeCurrent), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + ScopeType: util.Ptr(model.ScopeTypeTypeACCurrent), + } + + data, err = s.sut.GetDescriptionsForFilter(filter) + assert.Nil(s.T(), err) + assert.Equal(s.T(), 0, len(data)) +} + +func (s *MeasurementSuite) Test_GetLimitData() { + filter := model.MeasurementDescriptionDataType{ + MeasurementType: util.Ptr(model.MeasurementTypeTypeEnergy), + CommodityType: util.Ptr(model.CommodityTypeTypeElectricity), + ScopeType: util.Ptr(model.ScopeTypeTypeStateOfCharge), + } + + data := model.MeasurementDataType{} + err := s.sut.UpdateDataForFilter(data, nil, filter) + assert.NotNil(s.T(), err) + + data = model.MeasurementDataType{ + MeasurementId: util.Ptr(model.MeasurementIdType(100)), + } + err = s.sut.UpdateDataForFilter(data, nil, filter) + assert.NotNil(s.T(), err) + + mId := s.sut.AddDescription(filter) + assert.NotNil(s.T(), mId) + + descData, err := s.sut.GetDescriptionForId(*mId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), descData) + + result, err := s.sut.GetDataForId(*mId) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + data = model.MeasurementDataType{ + MeasurementId: mId, + ValueType: util.Ptr(model.MeasurementValueTypeTypeValue), + Value: model.NewScaledNumberType(16), + } + err = s.sut.UpdateDataForFilter(data, nil, filter) + assert.Nil(s.T(), err) + + result, err = s.sut.GetDataForId(*mId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + + result, err = s.sut.GetDataForId(model.MeasurementIdType(100)) + assert.NotNil(s.T(), err) + assert.Nil(s.T(), result) + + data = model.MeasurementDataType{} + delete := &model.MeasurementDataElementsType{ + Value: util.Ptr(model.ElementTagType{}), + } + err = s.sut.UpdateDataForId(data, delete, *mId) + assert.Nil(s.T(), err) + + result, err = s.sut.GetDataForId(*mId) + assert.Nil(s.T(), err) + assert.NotNil(s.T(), result) + assert.Nil(s.T(), result.Value) +} diff --git a/features/timeseries.go b/features/timeseries.go deleted file mode 100644 index b5c9a6fc..00000000 --- a/features/timeseries.go +++ /dev/null @@ -1,150 +0,0 @@ -package features - -import ( - "github.com/enbility/eebus-go/api" - spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/model" - "github.com/enbility/spine-go/spine" -) - -type TimeSeries struct { - *Feature -} - -// Get a new TimeSeries features helper -// -// - The feature on the local entity has to be of role client -// - The feature on the remote entity has to be of role server -func NewTimeSeries( - localEntity spineapi.EntityLocalInterface, - remoteEntity spineapi.EntityRemoteInterface) (*TimeSeries, error) { - feature, err := NewFeature(model.FeatureTypeTypeTimeSeries, localEntity, remoteEntity) - if err != nil { - return nil, err - } - - t := &TimeSeries{ - Feature: feature, - } - - return t, nil -} - -// request FunctionTypeTimeSeriesDescriptionListData from a remote entity -func (t *TimeSeries) RequestDescriptions() (*model.MsgCounterType, error) { - return t.requestData(model.FunctionTypeTimeSeriesDescriptionListData, nil, nil) -} - -// request FunctionTypeTimeSeriesConstraintsListData from a remote entity -func (t *TimeSeries) RequestConstraints() (*model.MsgCounterType, error) { - return t.requestData(model.FunctionTypeTimeSeriesConstraintsListData, nil, nil) -} - -// request FunctionTypeTimeSeriesListData from a remote device -func (t *TimeSeries) RequestValues() (*model.MsgCounterType, error) { - return t.requestData(model.FunctionTypeTimeSeriesListData, nil, nil) -} - -// write Time Series values -// returns an error if this failed -func (t *TimeSeries) WriteValues(data []model.TimeSeriesDataType) (*model.MsgCounterType, error) { - if len(data) == 0 { - return nil, api.ErrMissingData - } - - cmd := model.CmdType{ - TimeSeriesListData: &model.TimeSeriesListDataType{ - TimeSeriesData: data, - }, - } - - return t.remoteDevice.Sender().Write(t.featureLocal.Address(), t.featureRemote.Address(), cmd) -} - -// return current values for Time Series -func (t *TimeSeries) GetValues() ([]model.TimeSeriesDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.TimeSeriesListDataType](t.featureRemote, model.FunctionTypeTimeSeriesListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.TimeSeriesData, nil -} - -// return current value for a given TimeSeriesType -// there can only be one item matching the type -func (t *TimeSeries) GetValueForType(timeSeriesType model.TimeSeriesTypeType) (*model.TimeSeriesDataType, error) { - data, err := t.GetValues() - if err != nil { - return nil, err - } - - for _, item := range data { - if item.TimeSeriesId == nil { - continue - } - - desc, err := t.GetDescriptionForId(*item.TimeSeriesId) - if err != nil { - continue - } - - if desc.TimeSeriesType == nil || *desc.TimeSeriesType != timeSeriesType { - continue - } - - return &item, nil - } - - return nil, api.ErrDataNotAvailable -} - -// return list of descriptions -func (t *TimeSeries) GetDescriptions() ([]model.TimeSeriesDescriptionDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.TimeSeriesDescriptionListDataType](t.featureRemote, model.FunctionTypeTimeSeriesDescriptionListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.TimeSeriesDescriptionData, nil -} - -func (t *TimeSeries) GetDescriptionForId(id model.TimeSeriesIdType) (*model.TimeSeriesDescriptionDataType, error) { - data, err := t.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range data { - if item.TimeSeriesId != nil && *item.TimeSeriesId == id { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} - -func (t *TimeSeries) GetDescriptionForType(timeSeriesType model.TimeSeriesTypeType) (*model.TimeSeriesDescriptionDataType, error) { - data, err := t.GetDescriptions() - if err != nil { - return nil, err - } - - for _, item := range data { - if item.TimeSeriesType != nil && *item.TimeSeriesType == timeSeriesType { - return &item, nil - } - } - - return nil, api.ErrDataNotAvailable -} - -// return current constraints for Time Series -func (t *TimeSeries) GetConstraints() ([]model.TimeSeriesConstraintsDataType, error) { - data, err := spine.RemoteFeatureDataCopyOfType[*model.TimeSeriesConstraintsListDataType](t.featureRemote, model.FunctionTypeTimeSeriesConstraintsListData) - if err != nil { - return nil, api.ErrDataNotAvailable - } - - return data.TimeSeriesConstraintsData, nil -} diff --git a/go.mod b/go.mod index 2dcebb03..910b7742 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21.1 require ( github.com/enbility/ship-go v0.5.0 - github.com/enbility/spine-go v0.5.0 + github.com/enbility/spine-go v0.0.0-20240528063611-c1d0dbd2f600 github.com/stretchr/testify v1.8.4 ) diff --git a/go.sum b/go.sum index f9865682..4203c023 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/enbility/ship-go v0.5.0 h1:Uqol2XjzDOcvT8HUAE4B/59yqd3mxhpJJ/Q2eDHNGqc= github.com/enbility/ship-go v0.5.0/go.mod h1:ovyrJE3oPnGT5+eQnOqWut80gFDQ0XHn3ZWU2fHV9xQ= -github.com/enbility/spine-go v0.5.0 h1:3OQBl8gQPW/iuWmwcabmCIXDcFCP0RsDw7uP8BYUmaY= -github.com/enbility/spine-go v0.5.0/go.mod h1:8rXOJ7nTa4qrSRK0PpfavBXMztxi6l+h/IFpIVmHviM= +github.com/enbility/spine-go v0.0.0-20240528063611-c1d0dbd2f600 h1:fri20a6e1wyGdA8yA8X5/Ksz9Pku6A0mQjbcgabbgAo= +github.com/enbility/spine-go v0.0.0-20240528063611-c1d0dbd2f600/go.mod h1:8rXOJ7nTa4qrSRK0PpfavBXMztxi6l+h/IFpIVmHviM= github.com/enbility/zeroconf/v2 v2.0.0-20240210101930-d0004078577b h1:sg3c6LJ4eWffwtt9SW0lgcIX4Oh274vwdJnNFNNrDco= github.com/enbility/zeroconf/v2 v2.0.0-20240210101930-d0004078577b/go.mod h1:BjzRRiYX6mWdOgku1xxDE+NsV8PijTby7Q7BkYVdfDU= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= diff --git a/integration_tests/emobility_measurement_test.go b/integration_tests/emobility_measurement_test.go index fbbb2111..b30913fe 100644 --- a/integration_tests/emobility_measurement_test.go +++ b/integration_tests/emobility_measurement_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/enbility/eebus-go/features" + features "github.com/enbility/eebus-go/features/client" "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" @@ -81,7 +81,12 @@ func (s *EmobilityMeasurementSuite) TestGetValuesPerPhaseForScope() { measurement := model.MeasurementTypeTypeCurrent commodity := model.CommodityTypeTypeElectricity scope := model.ScopeTypeTypeACCurrent - data, err := s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) + filter := model.MeasurementDescriptionDataType{ + MeasurementType: &measurement, + CommodityType: &commodity, + ScopeType: &scope, + } + data, err := s.measurement.GetDataForFilter(filter) // Assert assert.Nil(s.T(), err) @@ -91,7 +96,9 @@ func (s *EmobilityMeasurementSuite) TestGetValuesPerPhaseForScope() { measurement = model.MeasurementTypeTypePower scope = model.ScopeTypeTypeACPower - data, err = s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) + filter.MeasurementType = &measurement + filter.ScopeType = &scope + data, err = s.measurement.GetDataForFilter(filter) // Assert assert.Nil(s.T(), err) @@ -101,7 +108,9 @@ func (s *EmobilityMeasurementSuite) TestGetValuesPerPhaseForScope() { measurement = model.MeasurementTypeTypeEnergy scope = model.ScopeTypeTypeCharge - data, err = s.measurement.GetValuesForTypeCommodityScope(measurement, commodity, scope) + filter.MeasurementType = &measurement + filter.ScopeType = &scope + data, err = s.measurement.GetDataForFilter(filter) // Assert assert.Nil(s.T(), err) diff --git a/mocks/DeviceClassificationClientInterface.go b/mocks/DeviceClassificationClientInterface.go new file mode 100644 index 00000000..7c9ef775 --- /dev/null +++ b/mocks/DeviceClassificationClientInterface.go @@ -0,0 +1,92 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceClassificationClientInterface is an autogenerated mock type for the DeviceClassificationClientInterface type +type DeviceClassificationClientInterface struct { + mock.Mock +} + +type DeviceClassificationClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceClassificationClientInterface) EXPECT() *DeviceClassificationClientInterface_Expecter { + return &DeviceClassificationClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestManufacturerDetails provides a mock function with given fields: +func (_m *DeviceClassificationClientInterface) RequestManufacturerDetails() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestManufacturerDetails") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceClassificationClientInterface_RequestManufacturerDetails_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestManufacturerDetails' +type DeviceClassificationClientInterface_RequestManufacturerDetails_Call struct { + *mock.Call +} + +// RequestManufacturerDetails is a helper method to define mock.On call +func (_e *DeviceClassificationClientInterface_Expecter) RequestManufacturerDetails() *DeviceClassificationClientInterface_RequestManufacturerDetails_Call { + return &DeviceClassificationClientInterface_RequestManufacturerDetails_Call{Call: _e.mock.On("RequestManufacturerDetails")} +} + +func (_c *DeviceClassificationClientInterface_RequestManufacturerDetails_Call) Run(run func()) *DeviceClassificationClientInterface_RequestManufacturerDetails_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceClassificationClientInterface_RequestManufacturerDetails_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceClassificationClientInterface_RequestManufacturerDetails_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceClassificationClientInterface_RequestManufacturerDetails_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *DeviceClassificationClientInterface_RequestManufacturerDetails_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceClassificationClientInterface creates a new instance of DeviceClassificationClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceClassificationClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceClassificationClientInterface { + mock := &DeviceClassificationClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceClassificationCommonInterface.go b/mocks/DeviceClassificationCommonInterface.go new file mode 100644 index 00000000..7a9d480b --- /dev/null +++ b/mocks/DeviceClassificationCommonInterface.go @@ -0,0 +1,92 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceClassificationCommonInterface is an autogenerated mock type for the DeviceClassificationCommonInterface type +type DeviceClassificationCommonInterface struct { + mock.Mock +} + +type DeviceClassificationCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceClassificationCommonInterface) EXPECT() *DeviceClassificationCommonInterface_Expecter { + return &DeviceClassificationCommonInterface_Expecter{mock: &_m.Mock} +} + +// GetManufacturerDetails provides a mock function with given fields: +func (_m *DeviceClassificationCommonInterface) GetManufacturerDetails() (*model.DeviceClassificationManufacturerDataType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetManufacturerDetails") + } + + var r0 *model.DeviceClassificationManufacturerDataType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.DeviceClassificationManufacturerDataType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.DeviceClassificationManufacturerDataType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceClassificationManufacturerDataType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceClassificationCommonInterface_GetManufacturerDetails_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetManufacturerDetails' +type DeviceClassificationCommonInterface_GetManufacturerDetails_Call struct { + *mock.Call +} + +// GetManufacturerDetails is a helper method to define mock.On call +func (_e *DeviceClassificationCommonInterface_Expecter) GetManufacturerDetails() *DeviceClassificationCommonInterface_GetManufacturerDetails_Call { + return &DeviceClassificationCommonInterface_GetManufacturerDetails_Call{Call: _e.mock.On("GetManufacturerDetails")} +} + +func (_c *DeviceClassificationCommonInterface_GetManufacturerDetails_Call) Run(run func()) *DeviceClassificationCommonInterface_GetManufacturerDetails_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceClassificationCommonInterface_GetManufacturerDetails_Call) Return(_a0 *model.DeviceClassificationManufacturerDataType, _a1 error) *DeviceClassificationCommonInterface_GetManufacturerDetails_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceClassificationCommonInterface_GetManufacturerDetails_Call) RunAndReturn(run func() (*model.DeviceClassificationManufacturerDataType, error)) *DeviceClassificationCommonInterface_GetManufacturerDetails_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceClassificationCommonInterface creates a new instance of DeviceClassificationCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceClassificationCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceClassificationCommonInterface { + mock := &DeviceClassificationCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceClassificationServerInterface.go b/mocks/DeviceClassificationServerInterface.go new file mode 100644 index 00000000..1d627a74 --- /dev/null +++ b/mocks/DeviceClassificationServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// DeviceClassificationServerInterface is an autogenerated mock type for the DeviceClassificationServerInterface type +type DeviceClassificationServerInterface struct { + mock.Mock +} + +type DeviceClassificationServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceClassificationServerInterface) EXPECT() *DeviceClassificationServerInterface_Expecter { + return &DeviceClassificationServerInterface_Expecter{mock: &_m.Mock} +} + +// NewDeviceClassificationServerInterface creates a new instance of DeviceClassificationServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceClassificationServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceClassificationServerInterface { + mock := &DeviceClassificationServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceConfigurationClientInterface.go b/mocks/DeviceConfigurationClientInterface.go new file mode 100644 index 00000000..da503a3a --- /dev/null +++ b/mocks/DeviceConfigurationClientInterface.go @@ -0,0 +1,486 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceConfigurationClientInterface is an autogenerated mock type for the DeviceConfigurationClientInterface type +type DeviceConfigurationClientInterface struct { + mock.Mock +} + +type DeviceConfigurationClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceConfigurationClientInterface) EXPECT() *DeviceConfigurationClientInterface_Expecter { + return &DeviceConfigurationClientInterface_Expecter{mock: &_m.Mock} +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *DeviceConfigurationClientInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *DeviceConfigurationClientInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { + return &DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationClientInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationClientInterface) GetKeyValueDataForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForFilter") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForFilter' +type DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDataForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationClientInterface_Expecter) GetKeyValueDataForFilter(filter interface{}) *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call { + return &DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call{Call: _e.mock.On("GetKeyValueDataForFilter", filter)} +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationClientInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationClientInterface) GetKeyValueDataForKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForKeyId' +type DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDataForKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationClientInterface_Expecter) GetKeyValueDataForKeyId(keyId interface{}) *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call { + return &DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call{Call: _e.mock.On("GetKeyValueDataForKeyId", keyId)} +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationClientInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionFoKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationClientInterface) GetKeyValueDescriptionFoKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionFoKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionFoKeyId' +type DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionFoKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationClientInterface_Expecter) GetKeyValueDescriptionFoKeyId(keyId interface{}) *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call { + return &DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call{Call: _e.mock.On("GetKeyValueDescriptionFoKeyId", keyId)} +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationClientInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionsForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationClientInterface) GetKeyValueDescriptionsForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionsForFilter") + } + + var r0 []model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) []model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionsForFilter' +type DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionsForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationClientInterface_Expecter) GetKeyValueDescriptionsForFilter(filter interface{}) *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call { + return &DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call{Call: _e.mock.On("GetKeyValueDescriptionsForFilter", filter)} +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call) Return(_a0 []model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationClientInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// RequestDescriptions provides a mock function with given fields: +func (_m *DeviceConfigurationClientInterface) RequestDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_RequestDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestDescriptions' +type DeviceConfigurationClientInterface_RequestDescriptions_Call struct { + *mock.Call +} + +// RequestDescriptions is a helper method to define mock.On call +func (_e *DeviceConfigurationClientInterface_Expecter) RequestDescriptions() *DeviceConfigurationClientInterface_RequestDescriptions_Call { + return &DeviceConfigurationClientInterface_RequestDescriptions_Call{Call: _e.mock.On("RequestDescriptions")} +} + +func (_c *DeviceConfigurationClientInterface_RequestDescriptions_Call) Run(run func()) *DeviceConfigurationClientInterface_RequestDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_RequestDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceConfigurationClientInterface_RequestDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_RequestDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *DeviceConfigurationClientInterface_RequestDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// RequestKeyValues provides a mock function with given fields: +func (_m *DeviceConfigurationClientInterface) RequestKeyValues() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestKeyValues") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_RequestKeyValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestKeyValues' +type DeviceConfigurationClientInterface_RequestKeyValues_Call struct { + *mock.Call +} + +// RequestKeyValues is a helper method to define mock.On call +func (_e *DeviceConfigurationClientInterface_Expecter) RequestKeyValues() *DeviceConfigurationClientInterface_RequestKeyValues_Call { + return &DeviceConfigurationClientInterface_RequestKeyValues_Call{Call: _e.mock.On("RequestKeyValues")} +} + +func (_c *DeviceConfigurationClientInterface_RequestKeyValues_Call) Run(run func()) *DeviceConfigurationClientInterface_RequestKeyValues_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_RequestKeyValues_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceConfigurationClientInterface_RequestKeyValues_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_RequestKeyValues_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *DeviceConfigurationClientInterface_RequestKeyValues_Call { + _c.Call.Return(run) + return _c +} + +// WriteKeyValues provides a mock function with given fields: data +func (_m *DeviceConfigurationClientInterface) WriteKeyValues(data []model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteKeyValues") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func([]model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func([]model.DeviceConfigurationKeyValueDataType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func([]model.DeviceConfigurationKeyValueDataType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationClientInterface_WriteKeyValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteKeyValues' +type DeviceConfigurationClientInterface_WriteKeyValues_Call struct { + *mock.Call +} + +// WriteKeyValues is a helper method to define mock.On call +// - data []model.DeviceConfigurationKeyValueDataType +func (_e *DeviceConfigurationClientInterface_Expecter) WriteKeyValues(data interface{}) *DeviceConfigurationClientInterface_WriteKeyValues_Call { + return &DeviceConfigurationClientInterface_WriteKeyValues_Call{Call: _e.mock.On("WriteKeyValues", data)} +} + +func (_c *DeviceConfigurationClientInterface_WriteKeyValues_Call) Run(run func(data []model.DeviceConfigurationKeyValueDataType)) *DeviceConfigurationClientInterface_WriteKeyValues_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]model.DeviceConfigurationKeyValueDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationClientInterface_WriteKeyValues_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceConfigurationClientInterface_WriteKeyValues_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationClientInterface_WriteKeyValues_Call) RunAndReturn(run func([]model.DeviceConfigurationKeyValueDataType) (*model.MsgCounterType, error)) *DeviceConfigurationClientInterface_WriteKeyValues_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceConfigurationClientInterface creates a new instance of DeviceConfigurationClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceConfigurationClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceConfigurationClientInterface { + mock := &DeviceConfigurationClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceConfigurationCommonInterface.go b/mocks/DeviceConfigurationCommonInterface.go new file mode 100644 index 00000000..160f3543 --- /dev/null +++ b/mocks/DeviceConfigurationCommonInterface.go @@ -0,0 +1,314 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceConfigurationCommonInterface is an autogenerated mock type for the DeviceConfigurationCommonInterface type +type DeviceConfigurationCommonInterface struct { + mock.Mock +} + +type DeviceConfigurationCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceConfigurationCommonInterface) EXPECT() *DeviceConfigurationCommonInterface_Expecter { + return &DeviceConfigurationCommonInterface_Expecter{mock: &_m.Mock} +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *DeviceConfigurationCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *DeviceConfigurationCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { + return &DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationCommonInterface) GetKeyValueDataForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForFilter") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForFilter' +type DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDataForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationCommonInterface_Expecter) GetKeyValueDataForFilter(filter interface{}) *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call { + return &DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call{Call: _e.mock.On("GetKeyValueDataForFilter", filter)} +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationCommonInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationCommonInterface) GetKeyValueDataForKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForKeyId' +type DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDataForKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationCommonInterface_Expecter) GetKeyValueDataForKeyId(keyId interface{}) *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call { + return &DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call{Call: _e.mock.On("GetKeyValueDataForKeyId", keyId)} +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationCommonInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionFoKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationCommonInterface) GetKeyValueDescriptionFoKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionFoKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionFoKeyId' +type DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionFoKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationCommonInterface_Expecter) GetKeyValueDescriptionFoKeyId(keyId interface{}) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call { + return &DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call{Call: _e.mock.On("GetKeyValueDescriptionFoKeyId", keyId)} +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionsForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationCommonInterface) GetKeyValueDescriptionsForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionsForFilter") + } + + var r0 []model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) []model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionsForFilter' +type DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionsForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationCommonInterface_Expecter) GetKeyValueDescriptionsForFilter(filter interface{}) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call { + return &DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call{Call: _e.mock.On("GetKeyValueDescriptionsForFilter", filter)} +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call) Return(_a0 []model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationCommonInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceConfigurationCommonInterface creates a new instance of DeviceConfigurationCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceConfigurationCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceConfigurationCommonInterface { + mock := &DeviceConfigurationCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceConfigurationServerInterface.go b/mocks/DeviceConfigurationServerInterface.go new file mode 100644 index 00000000..f2831ce9 --- /dev/null +++ b/mocks/DeviceConfigurationServerInterface.go @@ -0,0 +1,458 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceConfigurationServerInterface is an autogenerated mock type for the DeviceConfigurationServerInterface type +type DeviceConfigurationServerInterface struct { + mock.Mock +} + +type DeviceConfigurationServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceConfigurationServerInterface) EXPECT() *DeviceConfigurationServerInterface_Expecter { + return &DeviceConfigurationServerInterface_Expecter{mock: &_m.Mock} +} + +// AddKeyValueDescription provides a mock function with given fields: description +func (_m *DeviceConfigurationServerInterface) AddKeyValueDescription(description model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyIdType { + ret := _m.Called(description) + + if len(ret) == 0 { + panic("no return value specified for AddKeyValueDescription") + } + + var r0 *model.DeviceConfigurationKeyIdType + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyIdType); ok { + r0 = rf(description) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyIdType) + } + } + + return r0 +} + +// DeviceConfigurationServerInterface_AddKeyValueDescription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddKeyValueDescription' +type DeviceConfigurationServerInterface_AddKeyValueDescription_Call struct { + *mock.Call +} + +// AddKeyValueDescription is a helper method to define mock.On call +// - description model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationServerInterface_Expecter) AddKeyValueDescription(description interface{}) *DeviceConfigurationServerInterface_AddKeyValueDescription_Call { + return &DeviceConfigurationServerInterface_AddKeyValueDescription_Call{Call: _e.mock.On("AddKeyValueDescription", description)} +} + +func (_c *DeviceConfigurationServerInterface_AddKeyValueDescription_Call) Run(run func(description model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationServerInterface_AddKeyValueDescription_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_AddKeyValueDescription_Call) Return(_a0 *model.DeviceConfigurationKeyIdType) *DeviceConfigurationServerInterface_AddKeyValueDescription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationServerInterface_AddKeyValueDescription_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyIdType) *DeviceConfigurationServerInterface_AddKeyValueDescription_Call { + _c.Call.Return(run) + return _c +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *DeviceConfigurationServerInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *DeviceConfigurationServerInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { + return &DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *DeviceConfigurationServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationServerInterface) GetKeyValueDataForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForFilter") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForFilter' +type DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDataForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationServerInterface_Expecter) GetKeyValueDataForFilter(filter interface{}) *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call { + return &DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call{Call: _e.mock.On("GetKeyValueDataForFilter", filter)} +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationServerInterface_GetKeyValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDataForKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationServerInterface) GetKeyValueDataForKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDataForKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDataForKeyId' +type DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDataForKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationServerInterface_Expecter) GetKeyValueDataForKeyId(keyId interface{}) *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call { + return &DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call{Call: _e.mock.On("GetKeyValueDataForKeyId", keyId)} +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDataType, _a1 error) *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDataType, error)) *DeviceConfigurationServerInterface_GetKeyValueDataForKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionFoKeyId provides a mock function with given fields: keyId +func (_m *DeviceConfigurationServerInterface) GetKeyValueDescriptionFoKeyId(keyId model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(keyId) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionFoKeyId") + } + + var r0 *model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(keyId) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyIdType) *model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(keyId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyIdType) error); ok { + r1 = rf(keyId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionFoKeyId' +type DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionFoKeyId is a helper method to define mock.On call +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationServerInterface_Expecter) GetKeyValueDescriptionFoKeyId(keyId interface{}) *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call { + return &DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call{Call: _e.mock.On("GetKeyValueDescriptionFoKeyId", keyId)} +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call) Run(run func(keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call) Return(_a0 *model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyIdType) (*model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationServerInterface_GetKeyValueDescriptionFoKeyId_Call { + _c.Call.Return(run) + return _c +} + +// GetKeyValueDescriptionsForFilter provides a mock function with given fields: filter +func (_m *DeviceConfigurationServerInterface) GetKeyValueDescriptionsForFilter(filter model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetKeyValueDescriptionsForFilter") + } + + var r0 []model.DeviceConfigurationKeyValueDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDescriptionDataType) []model.DeviceConfigurationKeyValueDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.DeviceConfigurationKeyValueDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetKeyValueDescriptionsForFilter' +type DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetKeyValueDescriptionsForFilter is a helper method to define mock.On call +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationServerInterface_Expecter) GetKeyValueDescriptionsForFilter(filter interface{}) *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call { + return &DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call{Call: _e.mock.On("GetKeyValueDescriptionsForFilter", filter)} +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call) Run(run func(filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call) Return(_a0 []model.DeviceConfigurationKeyValueDescriptionDataType, _a1 error) *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDescriptionDataType) ([]model.DeviceConfigurationKeyValueDescriptionDataType, error)) *DeviceConfigurationServerInterface_GetKeyValueDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// UpdateKeyValueDataForFilter provides a mock function with given fields: data, deleteElements, filter +func (_m *DeviceConfigurationServerInterface) UpdateKeyValueDataForFilter(data model.DeviceConfigurationKeyValueDataType, deleteElements *model.DeviceConfigurationKeyValueDataElementsType, filter model.DeviceConfigurationKeyValueDescriptionDataType) error { + ret := _m.Called(data, deleteElements, filter) + + if len(ret) == 0 { + panic("no return value specified for UpdateKeyValueDataForFilter") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDataType, *model.DeviceConfigurationKeyValueDataElementsType, model.DeviceConfigurationKeyValueDescriptionDataType) error); ok { + r0 = rf(data, deleteElements, filter) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateKeyValueDataForFilter' +type DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call struct { + *mock.Call +} + +// UpdateKeyValueDataForFilter is a helper method to define mock.On call +// - data model.DeviceConfigurationKeyValueDataType +// - deleteElements *model.DeviceConfigurationKeyValueDataElementsType +// - filter model.DeviceConfigurationKeyValueDescriptionDataType +func (_e *DeviceConfigurationServerInterface_Expecter) UpdateKeyValueDataForFilter(data interface{}, deleteElements interface{}, filter interface{}) *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call { + return &DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call{Call: _e.mock.On("UpdateKeyValueDataForFilter", data, deleteElements, filter)} +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call) Run(run func(data model.DeviceConfigurationKeyValueDataType, deleteElements *model.DeviceConfigurationKeyValueDataElementsType, filter model.DeviceConfigurationKeyValueDescriptionDataType)) *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDataType), args[1].(*model.DeviceConfigurationKeyValueDataElementsType), args[2].(model.DeviceConfigurationKeyValueDescriptionDataType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call) Return(_a0 error) *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDataType, *model.DeviceConfigurationKeyValueDataElementsType, model.DeviceConfigurationKeyValueDescriptionDataType) error) *DeviceConfigurationServerInterface_UpdateKeyValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// UpdateKeyValueDataForKeyId provides a mock function with given fields: data, deleteElements, keyId +func (_m *DeviceConfigurationServerInterface) UpdateKeyValueDataForKeyId(data model.DeviceConfigurationKeyValueDataType, deleteElements *model.DeviceConfigurationKeyValueDataElementsType, keyId model.DeviceConfigurationKeyIdType) error { + ret := _m.Called(data, deleteElements, keyId) + + if len(ret) == 0 { + panic("no return value specified for UpdateKeyValueDataForKeyId") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.DeviceConfigurationKeyValueDataType, *model.DeviceConfigurationKeyValueDataElementsType, model.DeviceConfigurationKeyIdType) error); ok { + r0 = rf(data, deleteElements, keyId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateKeyValueDataForKeyId' +type DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call struct { + *mock.Call +} + +// UpdateKeyValueDataForKeyId is a helper method to define mock.On call +// - data model.DeviceConfigurationKeyValueDataType +// - deleteElements *model.DeviceConfigurationKeyValueDataElementsType +// - keyId model.DeviceConfigurationKeyIdType +func (_e *DeviceConfigurationServerInterface_Expecter) UpdateKeyValueDataForKeyId(data interface{}, deleteElements interface{}, keyId interface{}) *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call { + return &DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call{Call: _e.mock.On("UpdateKeyValueDataForKeyId", data, deleteElements, keyId)} +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call) Run(run func(data model.DeviceConfigurationKeyValueDataType, deleteElements *model.DeviceConfigurationKeyValueDataElementsType, keyId model.DeviceConfigurationKeyIdType)) *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.DeviceConfigurationKeyValueDataType), args[1].(*model.DeviceConfigurationKeyValueDataElementsType), args[2].(model.DeviceConfigurationKeyIdType)) + }) + return _c +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call) Return(_a0 error) *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call) RunAndReturn(run func(model.DeviceConfigurationKeyValueDataType, *model.DeviceConfigurationKeyValueDataElementsType, model.DeviceConfigurationKeyIdType) error) *DeviceConfigurationServerInterface_UpdateKeyValueDataForKeyId_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceConfigurationServerInterface creates a new instance of DeviceConfigurationServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceConfigurationServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceConfigurationServerInterface { + mock := &DeviceConfigurationServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceDiagnosisClientInterface.go b/mocks/DeviceDiagnosisClientInterface.go new file mode 100644 index 00000000..bba55da3 --- /dev/null +++ b/mocks/DeviceDiagnosisClientInterface.go @@ -0,0 +1,149 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceDiagnosisClientInterface is an autogenerated mock type for the DeviceDiagnosisClientInterface type +type DeviceDiagnosisClientInterface struct { + mock.Mock +} + +type DeviceDiagnosisClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceDiagnosisClientInterface) EXPECT() *DeviceDiagnosisClientInterface_Expecter { + return &DeviceDiagnosisClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestHeartbeat provides a mock function with given fields: +func (_m *DeviceDiagnosisClientInterface) RequestHeartbeat() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestHeartbeat") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceDiagnosisClientInterface_RequestHeartbeat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestHeartbeat' +type DeviceDiagnosisClientInterface_RequestHeartbeat_Call struct { + *mock.Call +} + +// RequestHeartbeat is a helper method to define mock.On call +func (_e *DeviceDiagnosisClientInterface_Expecter) RequestHeartbeat() *DeviceDiagnosisClientInterface_RequestHeartbeat_Call { + return &DeviceDiagnosisClientInterface_RequestHeartbeat_Call{Call: _e.mock.On("RequestHeartbeat")} +} + +func (_c *DeviceDiagnosisClientInterface_RequestHeartbeat_Call) Run(run func()) *DeviceDiagnosisClientInterface_RequestHeartbeat_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceDiagnosisClientInterface_RequestHeartbeat_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceDiagnosisClientInterface_RequestHeartbeat_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceDiagnosisClientInterface_RequestHeartbeat_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *DeviceDiagnosisClientInterface_RequestHeartbeat_Call { + _c.Call.Return(run) + return _c +} + +// RequestState provides a mock function with given fields: +func (_m *DeviceDiagnosisClientInterface) RequestState() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestState") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceDiagnosisClientInterface_RequestState_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestState' +type DeviceDiagnosisClientInterface_RequestState_Call struct { + *mock.Call +} + +// RequestState is a helper method to define mock.On call +func (_e *DeviceDiagnosisClientInterface_Expecter) RequestState() *DeviceDiagnosisClientInterface_RequestState_Call { + return &DeviceDiagnosisClientInterface_RequestState_Call{Call: _e.mock.On("RequestState")} +} + +func (_c *DeviceDiagnosisClientInterface_RequestState_Call) Run(run func()) *DeviceDiagnosisClientInterface_RequestState_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceDiagnosisClientInterface_RequestState_Call) Return(_a0 *model.MsgCounterType, _a1 error) *DeviceDiagnosisClientInterface_RequestState_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceDiagnosisClientInterface_RequestState_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *DeviceDiagnosisClientInterface_RequestState_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceDiagnosisClientInterface creates a new instance of DeviceDiagnosisClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceDiagnosisClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceDiagnosisClientInterface { + mock := &DeviceDiagnosisClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceDiagnosisCommonInterface.go b/mocks/DeviceDiagnosisCommonInterface.go new file mode 100644 index 00000000..d9a75ebd --- /dev/null +++ b/mocks/DeviceDiagnosisCommonInterface.go @@ -0,0 +1,140 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" + + time "time" +) + +// DeviceDiagnosisCommonInterface is an autogenerated mock type for the DeviceDiagnosisCommonInterface type +type DeviceDiagnosisCommonInterface struct { + mock.Mock +} + +type DeviceDiagnosisCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceDiagnosisCommonInterface) EXPECT() *DeviceDiagnosisCommonInterface_Expecter { + return &DeviceDiagnosisCommonInterface_Expecter{mock: &_m.Mock} +} + +// GetState provides a mock function with given fields: +func (_m *DeviceDiagnosisCommonInterface) GetState() (*model.DeviceDiagnosisStateDataType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetState") + } + + var r0 *model.DeviceDiagnosisStateDataType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.DeviceDiagnosisStateDataType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.DeviceDiagnosisStateDataType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.DeviceDiagnosisStateDataType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// DeviceDiagnosisCommonInterface_GetState_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetState' +type DeviceDiagnosisCommonInterface_GetState_Call struct { + *mock.Call +} + +// GetState is a helper method to define mock.On call +func (_e *DeviceDiagnosisCommonInterface_Expecter) GetState() *DeviceDiagnosisCommonInterface_GetState_Call { + return &DeviceDiagnosisCommonInterface_GetState_Call{Call: _e.mock.On("GetState")} +} + +func (_c *DeviceDiagnosisCommonInterface_GetState_Call) Run(run func()) *DeviceDiagnosisCommonInterface_GetState_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *DeviceDiagnosisCommonInterface_GetState_Call) Return(_a0 *model.DeviceDiagnosisStateDataType, _a1 error) *DeviceDiagnosisCommonInterface_GetState_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *DeviceDiagnosisCommonInterface_GetState_Call) RunAndReturn(run func() (*model.DeviceDiagnosisStateDataType, error)) *DeviceDiagnosisCommonInterface_GetState_Call { + _c.Call.Return(run) + return _c +} + +// IsHeartbeatWithinDuration provides a mock function with given fields: duration +func (_m *DeviceDiagnosisCommonInterface) IsHeartbeatWithinDuration(duration time.Duration) bool { + ret := _m.Called(duration) + + if len(ret) == 0 { + panic("no return value specified for IsHeartbeatWithinDuration") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(time.Duration) bool); ok { + r0 = rf(duration) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsHeartbeatWithinDuration' +type DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call struct { + *mock.Call +} + +// IsHeartbeatWithinDuration is a helper method to define mock.On call +// - duration time.Duration +func (_e *DeviceDiagnosisCommonInterface_Expecter) IsHeartbeatWithinDuration(duration interface{}) *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call { + return &DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call{Call: _e.mock.On("IsHeartbeatWithinDuration", duration)} +} + +func (_c *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call) Run(run func(duration time.Duration)) *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(time.Duration)) + }) + return _c +} + +func (_c *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call) Return(_a0 bool) *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call) RunAndReturn(run func(time.Duration) bool) *DeviceDiagnosisCommonInterface_IsHeartbeatWithinDuration_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceDiagnosisCommonInterface creates a new instance of DeviceDiagnosisCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceDiagnosisCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceDiagnosisCommonInterface { + mock := &DeviceDiagnosisCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/DeviceDiagnosisServerInterface.go b/mocks/DeviceDiagnosisServerInterface.go new file mode 100644 index 00000000..be7f2e1b --- /dev/null +++ b/mocks/DeviceDiagnosisServerInterface.go @@ -0,0 +1,68 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// DeviceDiagnosisServerInterface is an autogenerated mock type for the DeviceDiagnosisServerInterface type +type DeviceDiagnosisServerInterface struct { + mock.Mock +} + +type DeviceDiagnosisServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *DeviceDiagnosisServerInterface) EXPECT() *DeviceDiagnosisServerInterface_Expecter { + return &DeviceDiagnosisServerInterface_Expecter{mock: &_m.Mock} +} + +// SetLocalState provides a mock function with given fields: operatingState +func (_m *DeviceDiagnosisServerInterface) SetLocalState(operatingState *model.DeviceDiagnosisStateDataType) { + _m.Called(operatingState) +} + +// DeviceDiagnosisServerInterface_SetLocalState_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SetLocalState' +type DeviceDiagnosisServerInterface_SetLocalState_Call struct { + *mock.Call +} + +// SetLocalState is a helper method to define mock.On call +// - operatingState *model.DeviceDiagnosisStateDataType +func (_e *DeviceDiagnosisServerInterface_Expecter) SetLocalState(operatingState interface{}) *DeviceDiagnosisServerInterface_SetLocalState_Call { + return &DeviceDiagnosisServerInterface_SetLocalState_Call{Call: _e.mock.On("SetLocalState", operatingState)} +} + +func (_c *DeviceDiagnosisServerInterface_SetLocalState_Call) Run(run func(operatingState *model.DeviceDiagnosisStateDataType)) *DeviceDiagnosisServerInterface_SetLocalState_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*model.DeviceDiagnosisStateDataType)) + }) + return _c +} + +func (_c *DeviceDiagnosisServerInterface_SetLocalState_Call) Return() *DeviceDiagnosisServerInterface_SetLocalState_Call { + _c.Call.Return() + return _c +} + +func (_c *DeviceDiagnosisServerInterface_SetLocalState_Call) RunAndReturn(run func(*model.DeviceDiagnosisStateDataType)) *DeviceDiagnosisServerInterface_SetLocalState_Call { + _c.Call.Return(run) + return _c +} + +// NewDeviceDiagnosisServerInterface creates a new instance of DeviceDiagnosisServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewDeviceDiagnosisServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *DeviceDiagnosisServerInterface { + mock := &DeviceDiagnosisServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ElectricalConnectionClientInterface.go b/mocks/ElectricalConnectionClientInterface.go new file mode 100644 index 00000000..0c6f8f3e --- /dev/null +++ b/mocks/ElectricalConnectionClientInterface.go @@ -0,0 +1,263 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// ElectricalConnectionClientInterface is an autogenerated mock type for the ElectricalConnectionClientInterface type +type ElectricalConnectionClientInterface struct { + mock.Mock +} + +type ElectricalConnectionClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ElectricalConnectionClientInterface) EXPECT() *ElectricalConnectionClientInterface_Expecter { + return &ElectricalConnectionClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestCharacteristics provides a mock function with given fields: +func (_m *ElectricalConnectionClientInterface) RequestCharacteristics() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestCharacteristics") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionClientInterface_RequestCharacteristics_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestCharacteristics' +type ElectricalConnectionClientInterface_RequestCharacteristics_Call struct { + *mock.Call +} + +// RequestCharacteristics is a helper method to define mock.On call +func (_e *ElectricalConnectionClientInterface_Expecter) RequestCharacteristics() *ElectricalConnectionClientInterface_RequestCharacteristics_Call { + return &ElectricalConnectionClientInterface_RequestCharacteristics_Call{Call: _e.mock.On("RequestCharacteristics")} +} + +func (_c *ElectricalConnectionClientInterface_RequestCharacteristics_Call) Run(run func()) *ElectricalConnectionClientInterface_RequestCharacteristics_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestCharacteristics_Call) Return(_a0 *model.MsgCounterType, _a1 error) *ElectricalConnectionClientInterface_RequestCharacteristics_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestCharacteristics_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *ElectricalConnectionClientInterface_RequestCharacteristics_Call { + _c.Call.Return(run) + return _c +} + +// RequestDescriptions provides a mock function with given fields: +func (_m *ElectricalConnectionClientInterface) RequestDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionClientInterface_RequestDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestDescriptions' +type ElectricalConnectionClientInterface_RequestDescriptions_Call struct { + *mock.Call +} + +// RequestDescriptions is a helper method to define mock.On call +func (_e *ElectricalConnectionClientInterface_Expecter) RequestDescriptions() *ElectricalConnectionClientInterface_RequestDescriptions_Call { + return &ElectricalConnectionClientInterface_RequestDescriptions_Call{Call: _e.mock.On("RequestDescriptions")} +} + +func (_c *ElectricalConnectionClientInterface_RequestDescriptions_Call) Run(run func()) *ElectricalConnectionClientInterface_RequestDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *ElectricalConnectionClientInterface_RequestDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *ElectricalConnectionClientInterface_RequestDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// RequestParameterDescriptions provides a mock function with given fields: +func (_m *ElectricalConnectionClientInterface) RequestParameterDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestParameterDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionClientInterface_RequestParameterDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestParameterDescriptions' +type ElectricalConnectionClientInterface_RequestParameterDescriptions_Call struct { + *mock.Call +} + +// RequestParameterDescriptions is a helper method to define mock.On call +func (_e *ElectricalConnectionClientInterface_Expecter) RequestParameterDescriptions() *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call { + return &ElectricalConnectionClientInterface_RequestParameterDescriptions_Call{Call: _e.mock.On("RequestParameterDescriptions")} +} + +func (_c *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call) Run(run func()) *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *ElectricalConnectionClientInterface_RequestParameterDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// RequestPermittedValueSets provides a mock function with given fields: +func (_m *ElectricalConnectionClientInterface) RequestPermittedValueSets() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestPermittedValueSets") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionClientInterface_RequestPermittedValueSets_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestPermittedValueSets' +type ElectricalConnectionClientInterface_RequestPermittedValueSets_Call struct { + *mock.Call +} + +// RequestPermittedValueSets is a helper method to define mock.On call +func (_e *ElectricalConnectionClientInterface_Expecter) RequestPermittedValueSets() *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call { + return &ElectricalConnectionClientInterface_RequestPermittedValueSets_Call{Call: _e.mock.On("RequestPermittedValueSets")} +} + +func (_c *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call) Run(run func()) *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call) Return(_a0 *model.MsgCounterType, _a1 error) *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *ElectricalConnectionClientInterface_RequestPermittedValueSets_Call { + _c.Call.Return(run) + return _c +} + +// NewElectricalConnectionClientInterface creates a new instance of ElectricalConnectionClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewElectricalConnectionClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ElectricalConnectionClientInterface { + mock := &ElectricalConnectionClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ElectricalConnectionCommonInterface.go b/mocks/ElectricalConnectionCommonInterface.go new file mode 100644 index 00000000..e935739a --- /dev/null +++ b/mocks/ElectricalConnectionCommonInterface.go @@ -0,0 +1,564 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// ElectricalConnectionCommonInterface is an autogenerated mock type for the ElectricalConnectionCommonInterface type +type ElectricalConnectionCommonInterface struct { + mock.Mock +} + +type ElectricalConnectionCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ElectricalConnectionCommonInterface) EXPECT() *ElectricalConnectionCommonInterface_Expecter { + return &ElectricalConnectionCommonInterface_Expecter{mock: &_m.Mock} +} + +// AdjustValueToBeWithinPermittedValuesForParameterId provides a mock function with given fields: value, parameterId +func (_m *ElectricalConnectionCommonInterface) AdjustValueToBeWithinPermittedValuesForParameterId(value float64, parameterId model.ElectricalConnectionParameterIdType) float64 { + ret := _m.Called(value, parameterId) + + if len(ret) == 0 { + panic("no return value specified for AdjustValueToBeWithinPermittedValuesForParameterId") + } + + var r0 float64 + if rf, ok := ret.Get(0).(func(float64, model.ElectricalConnectionParameterIdType) float64); ok { + r0 = rf(value, parameterId) + } else { + r0 = ret.Get(0).(float64) + } + + return r0 +} + +// ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AdjustValueToBeWithinPermittedValuesForParameterId' +type ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call struct { + *mock.Call +} + +// AdjustValueToBeWithinPermittedValuesForParameterId is a helper method to define mock.On call +// - value float64 +// - parameterId model.ElectricalConnectionParameterIdType +func (_e *ElectricalConnectionCommonInterface_Expecter) AdjustValueToBeWithinPermittedValuesForParameterId(value interface{}, parameterId interface{}) *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + return &ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call{Call: _e.mock.On("AdjustValueToBeWithinPermittedValuesForParameterId", value, parameterId)} +} + +func (_c *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) Run(run func(value float64, parameterId model.ElectricalConnectionParameterIdType)) *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(model.ElectricalConnectionParameterIdType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) Return(_a0 float64) *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) RunAndReturn(run func(float64, model.ElectricalConnectionParameterIdType) float64) *ElectricalConnectionCommonInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Return(run) + return _c +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *ElectricalConnectionCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *ElectricalConnectionCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { + return &ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *ElectricalConnectionCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetCharacteristicsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetCharacteristicsForFilter(filter model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetCharacteristicsForFilter") + } + + var r0 []model.ElectricalConnectionCharacteristicDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) []model.ElectricalConnectionCharacteristicDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionCharacteristicDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionCharacteristicDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCharacteristicsForFilter' +type ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call struct { + *mock.Call +} + +// GetCharacteristicsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionCharacteristicDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetCharacteristicsForFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call { + return &ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call{Call: _e.mock.On("GetCharacteristicsForFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call) Run(run func(filter model.ElectricalConnectionCharacteristicDataType)) *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionCharacteristicDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call) Return(_a0 []model.ElectricalConnectionCharacteristicDataType, _a1 error) *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error)) *ElectricalConnectionCommonInterface_GetCharacteristicsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionForParameterDescriptionFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetDescriptionForParameterDescriptionFilter(filter model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionForParameterDescriptionFilter") + } + + var r0 *model.ElectricalConnectionDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) *model.ElectricalConnectionDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ElectricalConnectionDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionParameterDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionForParameterDescriptionFilter' +type ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call struct { + *mock.Call +} + +// GetDescriptionForParameterDescriptionFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionParameterDescriptionDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetDescriptionForParameterDescriptionFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call { + return &ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call{Call: _e.mock.On("GetDescriptionForParameterDescriptionFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call) Run(run func(filter model.ElectricalConnectionParameterDescriptionDataType)) *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionParameterDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call) Return(_a0 *model.ElectricalConnectionDescriptionDataType, _a1 error) *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call) RunAndReturn(run func(model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error)) *ElectricalConnectionCommonInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetDescriptionsForFilter(filter model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionsForFilter") + } + + var r0 []model.ElectricalConnectionDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionDescriptionDataType) []model.ElectricalConnectionDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionsForFilter' +type ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetDescriptionsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionDescriptionDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetDescriptionsForFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call { + return &ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call{Call: _e.mock.On("GetDescriptionsForFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call) Run(run func(filter model.ElectricalConnectionDescriptionDataType)) *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call) Return(_a0 []model.ElectricalConnectionDescriptionDataType, _a1 error) *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error)) *ElectricalConnectionCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetParameterDescriptionsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetParameterDescriptionsForFilter(filter model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetParameterDescriptionsForFilter") + } + + var r0 []model.ElectricalConnectionParameterDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) []model.ElectricalConnectionParameterDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionParameterDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionParameterDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetParameterDescriptionsForFilter' +type ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetParameterDescriptionsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionParameterDescriptionDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetParameterDescriptionsForFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call { + return &ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call{Call: _e.mock.On("GetParameterDescriptionsForFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call) Run(run func(filter model.ElectricalConnectionParameterDescriptionDataType)) *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionParameterDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call) Return(_a0 []model.ElectricalConnectionParameterDescriptionDataType, _a1 error) *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error)) *ElectricalConnectionCommonInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPermittedValueDataForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetPermittedValueDataForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetPermittedValueDataForFilter") + } + + var r0 float64 + var r1 float64 + var r2 float64 + var r3 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r0 = rf(filter) + } else { + r0 = ret.Get(0).(float64) + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r1 = rf(filter) + } else { + r1 = ret.Get(1).(float64) + } + + if rf, ok := ret.Get(2).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r2 = rf(filter) + } else { + r2 = ret.Get(2).(float64) + } + + if rf, ok := ret.Get(3).(func(model.ElectricalConnectionPermittedValueSetDataType) error); ok { + r3 = rf(filter) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPermittedValueDataForFilter' +type ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call struct { + *mock.Call +} + +// GetPermittedValueDataForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionPermittedValueSetDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetPermittedValueDataForFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call { + return &ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call{Call: _e.mock.On("GetPermittedValueDataForFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call) Run(run func(filter model.ElectricalConnectionPermittedValueSetDataType)) *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionPermittedValueSetDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call) Return(_a0 float64, _a1 float64, _a2 float64, _a3 error) *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error)) *ElectricalConnectionCommonInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPermittedValueSetForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionCommonInterface) GetPermittedValueSetForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetPermittedValueSetForFilter") + } + + var r0 []model.ElectricalConnectionPermittedValueSetDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) []model.ElectricalConnectionPermittedValueSetDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionPermittedValueSetDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionPermittedValueSetDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPermittedValueSetForFilter' +type ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call struct { + *mock.Call +} + +// GetPermittedValueSetForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionPermittedValueSetDataType +func (_e *ElectricalConnectionCommonInterface_Expecter) GetPermittedValueSetForFilter(filter interface{}) *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call { + return &ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call{Call: _e.mock.On("GetPermittedValueSetForFilter", filter)} +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call) Run(run func(filter model.ElectricalConnectionPermittedValueSetDataType)) *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionPermittedValueSetDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call) Return(_a0 []model.ElectricalConnectionPermittedValueSetDataType, _a1 error) *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error)) *ElectricalConnectionCommonInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPhaseCurrentLimits provides a mock function with given fields: +func (_m *ElectricalConnectionCommonInterface) GetPhaseCurrentLimits() ([]float64, []float64, []float64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPhaseCurrentLimits") + } + + var r0 []float64 + var r1 []float64 + var r2 []float64 + var r3 error + if rf, ok := ret.Get(0).(func() ([]float64, []float64, []float64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []float64); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]float64) + } + } + + if rf, ok := ret.Get(1).(func() []float64); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]float64) + } + } + + if rf, ok := ret.Get(2).(func() []float64); ok { + r2 = rf() + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]float64) + } + } + + if rf, ok := ret.Get(3).(func() error); ok { + r3 = rf() + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPhaseCurrentLimits' +type ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call struct { + *mock.Call +} + +// GetPhaseCurrentLimits is a helper method to define mock.On call +func (_e *ElectricalConnectionCommonInterface_Expecter) GetPhaseCurrentLimits() *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call { + return &ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call{Call: _e.mock.On("GetPhaseCurrentLimits")} +} + +func (_c *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call) Run(run func()) *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call) Return(resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error) *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call { + _c.Call.Return(resultMin, resultMax, resultDefault, resultErr) + return _c +} + +func (_c *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call) RunAndReturn(run func() ([]float64, []float64, []float64, error)) *ElectricalConnectionCommonInterface_GetPhaseCurrentLimits_Call { + _c.Call.Return(run) + return _c +} + +// NewElectricalConnectionCommonInterface creates a new instance of ElectricalConnectionCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewElectricalConnectionCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ElectricalConnectionCommonInterface { + mock := &ElectricalConnectionCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ElectricalConnectionServerInterface.go b/mocks/ElectricalConnectionServerInterface.go new file mode 100644 index 00000000..eee852f0 --- /dev/null +++ b/mocks/ElectricalConnectionServerInterface.go @@ -0,0 +1,763 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// ElectricalConnectionServerInterface is an autogenerated mock type for the ElectricalConnectionServerInterface type +type ElectricalConnectionServerInterface struct { + mock.Mock +} + +type ElectricalConnectionServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *ElectricalConnectionServerInterface) EXPECT() *ElectricalConnectionServerInterface_Expecter { + return &ElectricalConnectionServerInterface_Expecter{mock: &_m.Mock} +} + +// AddCharacteristic provides a mock function with given fields: data +func (_m *ElectricalConnectionServerInterface) AddCharacteristic(data model.ElectricalConnectionCharacteristicDataType) (*model.ElectricalConnectionCharacteristicIdType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for AddCharacteristic") + } + + var r0 *model.ElectricalConnectionCharacteristicIdType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) (*model.ElectricalConnectionCharacteristicIdType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) *model.ElectricalConnectionCharacteristicIdType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ElectricalConnectionCharacteristicIdType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionCharacteristicDataType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_AddCharacteristic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddCharacteristic' +type ElectricalConnectionServerInterface_AddCharacteristic_Call struct { + *mock.Call +} + +// AddCharacteristic is a helper method to define mock.On call +// - data model.ElectricalConnectionCharacteristicDataType +func (_e *ElectricalConnectionServerInterface_Expecter) AddCharacteristic(data interface{}) *ElectricalConnectionServerInterface_AddCharacteristic_Call { + return &ElectricalConnectionServerInterface_AddCharacteristic_Call{Call: _e.mock.On("AddCharacteristic", data)} +} + +func (_c *ElectricalConnectionServerInterface_AddCharacteristic_Call) Run(run func(data model.ElectricalConnectionCharacteristicDataType)) *ElectricalConnectionServerInterface_AddCharacteristic_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionCharacteristicDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddCharacteristic_Call) Return(_a0 *model.ElectricalConnectionCharacteristicIdType, _a1 error) *ElectricalConnectionServerInterface_AddCharacteristic_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddCharacteristic_Call) RunAndReturn(run func(model.ElectricalConnectionCharacteristicDataType) (*model.ElectricalConnectionCharacteristicIdType, error)) *ElectricalConnectionServerInterface_AddCharacteristic_Call { + _c.Call.Return(run) + return _c +} + +// AddDescription provides a mock function with given fields: description +func (_m *ElectricalConnectionServerInterface) AddDescription(description model.ElectricalConnectionDescriptionDataType) error { + ret := _m.Called(description) + + if len(ret) == 0 { + panic("no return value specified for AddDescription") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionDescriptionDataType) error); ok { + r0 = rf(description) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ElectricalConnectionServerInterface_AddDescription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddDescription' +type ElectricalConnectionServerInterface_AddDescription_Call struct { + *mock.Call +} + +// AddDescription is a helper method to define mock.On call +// - description model.ElectricalConnectionDescriptionDataType +func (_e *ElectricalConnectionServerInterface_Expecter) AddDescription(description interface{}) *ElectricalConnectionServerInterface_AddDescription_Call { + return &ElectricalConnectionServerInterface_AddDescription_Call{Call: _e.mock.On("AddDescription", description)} +} + +func (_c *ElectricalConnectionServerInterface_AddDescription_Call) Run(run func(description model.ElectricalConnectionDescriptionDataType)) *ElectricalConnectionServerInterface_AddDescription_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddDescription_Call) Return(_a0 error) *ElectricalConnectionServerInterface_AddDescription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddDescription_Call) RunAndReturn(run func(model.ElectricalConnectionDescriptionDataType) error) *ElectricalConnectionServerInterface_AddDescription_Call { + _c.Call.Return(run) + return _c +} + +// AddParameterDescription provides a mock function with given fields: description +func (_m *ElectricalConnectionServerInterface) AddParameterDescription(description model.ElectricalConnectionParameterDescriptionDataType) *model.ElectricalConnectionParameterIdType { + ret := _m.Called(description) + + if len(ret) == 0 { + panic("no return value specified for AddParameterDescription") + } + + var r0 *model.ElectricalConnectionParameterIdType + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) *model.ElectricalConnectionParameterIdType); ok { + r0 = rf(description) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ElectricalConnectionParameterIdType) + } + } + + return r0 +} + +// ElectricalConnectionServerInterface_AddParameterDescription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddParameterDescription' +type ElectricalConnectionServerInterface_AddParameterDescription_Call struct { + *mock.Call +} + +// AddParameterDescription is a helper method to define mock.On call +// - description model.ElectricalConnectionParameterDescriptionDataType +func (_e *ElectricalConnectionServerInterface_Expecter) AddParameterDescription(description interface{}) *ElectricalConnectionServerInterface_AddParameterDescription_Call { + return &ElectricalConnectionServerInterface_AddParameterDescription_Call{Call: _e.mock.On("AddParameterDescription", description)} +} + +func (_c *ElectricalConnectionServerInterface_AddParameterDescription_Call) Run(run func(description model.ElectricalConnectionParameterDescriptionDataType)) *ElectricalConnectionServerInterface_AddParameterDescription_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionParameterDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddParameterDescription_Call) Return(_a0 *model.ElectricalConnectionParameterIdType) *ElectricalConnectionServerInterface_AddParameterDescription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AddParameterDescription_Call) RunAndReturn(run func(model.ElectricalConnectionParameterDescriptionDataType) *model.ElectricalConnectionParameterIdType) *ElectricalConnectionServerInterface_AddParameterDescription_Call { + _c.Call.Return(run) + return _c +} + +// AdjustValueToBeWithinPermittedValuesForParameterId provides a mock function with given fields: value, parameterId +func (_m *ElectricalConnectionServerInterface) AdjustValueToBeWithinPermittedValuesForParameterId(value float64, parameterId model.ElectricalConnectionParameterIdType) float64 { + ret := _m.Called(value, parameterId) + + if len(ret) == 0 { + panic("no return value specified for AdjustValueToBeWithinPermittedValuesForParameterId") + } + + var r0 float64 + if rf, ok := ret.Get(0).(func(float64, model.ElectricalConnectionParameterIdType) float64); ok { + r0 = rf(value, parameterId) + } else { + r0 = ret.Get(0).(float64) + } + + return r0 +} + +// ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AdjustValueToBeWithinPermittedValuesForParameterId' +type ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call struct { + *mock.Call +} + +// AdjustValueToBeWithinPermittedValuesForParameterId is a helper method to define mock.On call +// - value float64 +// - parameterId model.ElectricalConnectionParameterIdType +func (_e *ElectricalConnectionServerInterface_Expecter) AdjustValueToBeWithinPermittedValuesForParameterId(value interface{}, parameterId interface{}) *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + return &ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call{Call: _e.mock.On("AdjustValueToBeWithinPermittedValuesForParameterId", value, parameterId)} +} + +func (_c *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) Run(run func(value float64, parameterId model.ElectricalConnectionParameterIdType)) *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(float64), args[1].(model.ElectricalConnectionParameterIdType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) Return(_a0 float64) *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call) RunAndReturn(run func(float64, model.ElectricalConnectionParameterIdType) float64) *ElectricalConnectionServerInterface_AdjustValueToBeWithinPermittedValuesForParameterId_Call { + _c.Call.Return(run) + return _c +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *ElectricalConnectionServerInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *ElectricalConnectionServerInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { + return &ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *ElectricalConnectionServerInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetCharacteristicsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetCharacteristicsForFilter(filter model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetCharacteristicsForFilter") + } + + var r0 []model.ElectricalConnectionCharacteristicDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType) []model.ElectricalConnectionCharacteristicDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionCharacteristicDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionCharacteristicDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetCharacteristicsForFilter' +type ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call struct { + *mock.Call +} + +// GetCharacteristicsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionCharacteristicDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetCharacteristicsForFilter(filter interface{}) *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call { + return &ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call{Call: _e.mock.On("GetCharacteristicsForFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call) Run(run func(filter model.ElectricalConnectionCharacteristicDataType)) *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionCharacteristicDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call) Return(_a0 []model.ElectricalConnectionCharacteristicDataType, _a1 error) *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionCharacteristicDataType) ([]model.ElectricalConnectionCharacteristicDataType, error)) *ElectricalConnectionServerInterface_GetCharacteristicsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionForParameterDescriptionFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetDescriptionForParameterDescriptionFilter(filter model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionForParameterDescriptionFilter") + } + + var r0 *model.ElectricalConnectionDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) *model.ElectricalConnectionDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.ElectricalConnectionDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionParameterDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionForParameterDescriptionFilter' +type ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call struct { + *mock.Call +} + +// GetDescriptionForParameterDescriptionFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionParameterDescriptionDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetDescriptionForParameterDescriptionFilter(filter interface{}) *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call { + return &ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call{Call: _e.mock.On("GetDescriptionForParameterDescriptionFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call) Run(run func(filter model.ElectricalConnectionParameterDescriptionDataType)) *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionParameterDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call) Return(_a0 *model.ElectricalConnectionDescriptionDataType, _a1 error) *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call) RunAndReturn(run func(model.ElectricalConnectionParameterDescriptionDataType) (*model.ElectricalConnectionDescriptionDataType, error)) *ElectricalConnectionServerInterface_GetDescriptionForParameterDescriptionFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetDescriptionsForFilter(filter model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionsForFilter") + } + + var r0 []model.ElectricalConnectionDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionDescriptionDataType) []model.ElectricalConnectionDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionsForFilter' +type ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetDescriptionsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionDescriptionDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetDescriptionsForFilter(filter interface{}) *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call { + return &ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call{Call: _e.mock.On("GetDescriptionsForFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call) Run(run func(filter model.ElectricalConnectionDescriptionDataType)) *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call) Return(_a0 []model.ElectricalConnectionDescriptionDataType, _a1 error) *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionDescriptionDataType) ([]model.ElectricalConnectionDescriptionDataType, error)) *ElectricalConnectionServerInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetParameterDescriptionsForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetParameterDescriptionsForFilter(filter model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetParameterDescriptionsForFilter") + } + + var r0 []model.ElectricalConnectionParameterDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionParameterDescriptionDataType) []model.ElectricalConnectionParameterDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionParameterDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionParameterDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetParameterDescriptionsForFilter' +type ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetParameterDescriptionsForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionParameterDescriptionDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetParameterDescriptionsForFilter(filter interface{}) *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call { + return &ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call{Call: _e.mock.On("GetParameterDescriptionsForFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call) Run(run func(filter model.ElectricalConnectionParameterDescriptionDataType)) *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionParameterDescriptionDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call) Return(_a0 []model.ElectricalConnectionParameterDescriptionDataType, _a1 error) *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionParameterDescriptionDataType) ([]model.ElectricalConnectionParameterDescriptionDataType, error)) *ElectricalConnectionServerInterface_GetParameterDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPermittedValueDataForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetPermittedValueDataForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetPermittedValueDataForFilter") + } + + var r0 float64 + var r1 float64 + var r2 float64 + var r3 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r0 = rf(filter) + } else { + r0 = ret.Get(0).(float64) + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r1 = rf(filter) + } else { + r1 = ret.Get(1).(float64) + } + + if rf, ok := ret.Get(2).(func(model.ElectricalConnectionPermittedValueSetDataType) float64); ok { + r2 = rf(filter) + } else { + r2 = ret.Get(2).(float64) + } + + if rf, ok := ret.Get(3).(func(model.ElectricalConnectionPermittedValueSetDataType) error); ok { + r3 = rf(filter) + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPermittedValueDataForFilter' +type ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call struct { + *mock.Call +} + +// GetPermittedValueDataForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionPermittedValueSetDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetPermittedValueDataForFilter(filter interface{}) *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call { + return &ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call{Call: _e.mock.On("GetPermittedValueDataForFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call) Run(run func(filter model.ElectricalConnectionPermittedValueSetDataType)) *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionPermittedValueSetDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call) Return(_a0 float64, _a1 float64, _a2 float64, _a3 error) *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Return(_a0, _a1, _a2, _a3) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionPermittedValueSetDataType) (float64, float64, float64, error)) *ElectricalConnectionServerInterface_GetPermittedValueDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPermittedValueSetForFilter provides a mock function with given fields: filter +func (_m *ElectricalConnectionServerInterface) GetPermittedValueSetForFilter(filter model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetPermittedValueSetForFilter") + } + + var r0 []model.ElectricalConnectionPermittedValueSetDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionPermittedValueSetDataType) []model.ElectricalConnectionPermittedValueSetDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.ElectricalConnectionPermittedValueSetDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.ElectricalConnectionPermittedValueSetDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPermittedValueSetForFilter' +type ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call struct { + *mock.Call +} + +// GetPermittedValueSetForFilter is a helper method to define mock.On call +// - filter model.ElectricalConnectionPermittedValueSetDataType +func (_e *ElectricalConnectionServerInterface_Expecter) GetPermittedValueSetForFilter(filter interface{}) *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call { + return &ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call{Call: _e.mock.On("GetPermittedValueSetForFilter", filter)} +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call) Run(run func(filter model.ElectricalConnectionPermittedValueSetDataType)) *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionPermittedValueSetDataType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call) Return(_a0 []model.ElectricalConnectionPermittedValueSetDataType, _a1 error) *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call) RunAndReturn(run func(model.ElectricalConnectionPermittedValueSetDataType) ([]model.ElectricalConnectionPermittedValueSetDataType, error)) *ElectricalConnectionServerInterface_GetPermittedValueSetForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetPhaseCurrentLimits provides a mock function with given fields: +func (_m *ElectricalConnectionServerInterface) GetPhaseCurrentLimits() ([]float64, []float64, []float64, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetPhaseCurrentLimits") + } + + var r0 []float64 + var r1 []float64 + var r2 []float64 + var r3 error + if rf, ok := ret.Get(0).(func() ([]float64, []float64, []float64, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []float64); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]float64) + } + } + + if rf, ok := ret.Get(1).(func() []float64); ok { + r1 = rf() + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).([]float64) + } + } + + if rf, ok := ret.Get(2).(func() []float64); ok { + r2 = rf() + } else { + if ret.Get(2) != nil { + r2 = ret.Get(2).([]float64) + } + } + + if rf, ok := ret.Get(3).(func() error); ok { + r3 = rf() + } else { + r3 = ret.Error(3) + } + + return r0, r1, r2, r3 +} + +// ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetPhaseCurrentLimits' +type ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call struct { + *mock.Call +} + +// GetPhaseCurrentLimits is a helper method to define mock.On call +func (_e *ElectricalConnectionServerInterface_Expecter) GetPhaseCurrentLimits() *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call { + return &ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call{Call: _e.mock.On("GetPhaseCurrentLimits")} +} + +func (_c *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call) Run(run func()) *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call) Return(resultMin []float64, resultMax []float64, resultDefault []float64, resultErr error) *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call { + _c.Call.Return(resultMin, resultMax, resultDefault, resultErr) + return _c +} + +func (_c *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call) RunAndReturn(run func() ([]float64, []float64, []float64, error)) *ElectricalConnectionServerInterface_GetPhaseCurrentLimits_Call { + _c.Call.Return(run) + return _c +} + +// UpdateCharacteristic provides a mock function with given fields: data, deleteElements +func (_m *ElectricalConnectionServerInterface) UpdateCharacteristic(data model.ElectricalConnectionCharacteristicDataType, deleteElements *model.ElectricalConnectionCharacteristicDataElementsType) error { + ret := _m.Called(data, deleteElements) + + if len(ret) == 0 { + panic("no return value specified for UpdateCharacteristic") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.ElectricalConnectionCharacteristicDataType, *model.ElectricalConnectionCharacteristicDataElementsType) error); ok { + r0 = rf(data, deleteElements) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// ElectricalConnectionServerInterface_UpdateCharacteristic_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateCharacteristic' +type ElectricalConnectionServerInterface_UpdateCharacteristic_Call struct { + *mock.Call +} + +// UpdateCharacteristic is a helper method to define mock.On call +// - data model.ElectricalConnectionCharacteristicDataType +// - deleteElements *model.ElectricalConnectionCharacteristicDataElementsType +func (_e *ElectricalConnectionServerInterface_Expecter) UpdateCharacteristic(data interface{}, deleteElements interface{}) *ElectricalConnectionServerInterface_UpdateCharacteristic_Call { + return &ElectricalConnectionServerInterface_UpdateCharacteristic_Call{Call: _e.mock.On("UpdateCharacteristic", data, deleteElements)} +} + +func (_c *ElectricalConnectionServerInterface_UpdateCharacteristic_Call) Run(run func(data model.ElectricalConnectionCharacteristicDataType, deleteElements *model.ElectricalConnectionCharacteristicDataElementsType)) *ElectricalConnectionServerInterface_UpdateCharacteristic_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.ElectricalConnectionCharacteristicDataType), args[1].(*model.ElectricalConnectionCharacteristicDataElementsType)) + }) + return _c +} + +func (_c *ElectricalConnectionServerInterface_UpdateCharacteristic_Call) Return(_a0 error) *ElectricalConnectionServerInterface_UpdateCharacteristic_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ElectricalConnectionServerInterface_UpdateCharacteristic_Call) RunAndReturn(run func(model.ElectricalConnectionCharacteristicDataType, *model.ElectricalConnectionCharacteristicDataElementsType) error) *ElectricalConnectionServerInterface_UpdateCharacteristic_Call { + _c.Call.Return(run) + return _c +} + +// NewElectricalConnectionServerInterface creates a new instance of ElectricalConnectionServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewElectricalConnectionServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *ElectricalConnectionServerInterface { + mock := &ElectricalConnectionServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/FeatureClientInterface.go b/mocks/FeatureClientInterface.go new file mode 100644 index 00000000..05601422 --- /dev/null +++ b/mocks/FeatureClientInterface.go @@ -0,0 +1,322 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + api "github.com/enbility/spine-go/api" + + mock "github.com/stretchr/testify/mock" + + model "github.com/enbility/spine-go/model" +) + +// FeatureClientInterface is an autogenerated mock type for the FeatureClientInterface type +type FeatureClientInterface struct { + mock.Mock +} + +type FeatureClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *FeatureClientInterface) EXPECT() *FeatureClientInterface_Expecter { + return &FeatureClientInterface_Expecter{mock: &_m.Mock} +} + +// AddResponseCallback provides a mock function with given fields: msgCounterReference, function +func (_m *FeatureClientInterface) AddResponseCallback(msgCounterReference model.MsgCounterType, function func(api.ResponseMessage)) error { + ret := _m.Called(msgCounterReference, function) + + if len(ret) == 0 { + panic("no return value specified for AddResponseCallback") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.MsgCounterType, func(api.ResponseMessage)) error); ok { + r0 = rf(msgCounterReference, function) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// FeatureClientInterface_AddResponseCallback_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddResponseCallback' +type FeatureClientInterface_AddResponseCallback_Call struct { + *mock.Call +} + +// AddResponseCallback is a helper method to define mock.On call +// - msgCounterReference model.MsgCounterType +// - function func(api.ResponseMessage) +func (_e *FeatureClientInterface_Expecter) AddResponseCallback(msgCounterReference interface{}, function interface{}) *FeatureClientInterface_AddResponseCallback_Call { + return &FeatureClientInterface_AddResponseCallback_Call{Call: _e.mock.On("AddResponseCallback", msgCounterReference, function)} +} + +func (_c *FeatureClientInterface_AddResponseCallback_Call) Run(run func(msgCounterReference model.MsgCounterType, function func(api.ResponseMessage))) *FeatureClientInterface_AddResponseCallback_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MsgCounterType), args[1].(func(api.ResponseMessage))) + }) + return _c +} + +func (_c *FeatureClientInterface_AddResponseCallback_Call) Return(_a0 error) *FeatureClientInterface_AddResponseCallback_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *FeatureClientInterface_AddResponseCallback_Call) RunAndReturn(run func(model.MsgCounterType, func(api.ResponseMessage)) error) *FeatureClientInterface_AddResponseCallback_Call { + _c.Call.Return(run) + return _c +} + +// AddResultCallback provides a mock function with given fields: function +func (_m *FeatureClientInterface) AddResultCallback(function func(api.ResponseMessage)) { + _m.Called(function) +} + +// FeatureClientInterface_AddResultCallback_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddResultCallback' +type FeatureClientInterface_AddResultCallback_Call struct { + *mock.Call +} + +// AddResultCallback is a helper method to define mock.On call +// - function func(api.ResponseMessage) +func (_e *FeatureClientInterface_Expecter) AddResultCallback(function interface{}) *FeatureClientInterface_AddResultCallback_Call { + return &FeatureClientInterface_AddResultCallback_Call{Call: _e.mock.On("AddResultCallback", function)} +} + +func (_c *FeatureClientInterface_AddResultCallback_Call) Run(run func(function func(api.ResponseMessage))) *FeatureClientInterface_AddResultCallback_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(func(api.ResponseMessage))) + }) + return _c +} + +func (_c *FeatureClientInterface_AddResultCallback_Call) Return() *FeatureClientInterface_AddResultCallback_Call { + _c.Call.Return() + return _c +} + +func (_c *FeatureClientInterface_AddResultCallback_Call) RunAndReturn(run func(func(api.ResponseMessage))) *FeatureClientInterface_AddResultCallback_Call { + _c.Call.Return(run) + return _c +} + +// Bind provides a mock function with given fields: +func (_m *FeatureClientInterface) Bind() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Bind") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FeatureClientInterface_Bind_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Bind' +type FeatureClientInterface_Bind_Call struct { + *mock.Call +} + +// Bind is a helper method to define mock.On call +func (_e *FeatureClientInterface_Expecter) Bind() *FeatureClientInterface_Bind_Call { + return &FeatureClientInterface_Bind_Call{Call: _e.mock.On("Bind")} +} + +func (_c *FeatureClientInterface_Bind_Call) Run(run func()) *FeatureClientInterface_Bind_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *FeatureClientInterface_Bind_Call) Return(_a0 *model.MsgCounterType, _a1 error) *FeatureClientInterface_Bind_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *FeatureClientInterface_Bind_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *FeatureClientInterface_Bind_Call { + _c.Call.Return(run) + return _c +} + +// HasBinding provides a mock function with given fields: +func (_m *FeatureClientInterface) HasBinding() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for HasBinding") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// FeatureClientInterface_HasBinding_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasBinding' +type FeatureClientInterface_HasBinding_Call struct { + *mock.Call +} + +// HasBinding is a helper method to define mock.On call +func (_e *FeatureClientInterface_Expecter) HasBinding() *FeatureClientInterface_HasBinding_Call { + return &FeatureClientInterface_HasBinding_Call{Call: _e.mock.On("HasBinding")} +} + +func (_c *FeatureClientInterface_HasBinding_Call) Run(run func()) *FeatureClientInterface_HasBinding_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *FeatureClientInterface_HasBinding_Call) Return(_a0 bool) *FeatureClientInterface_HasBinding_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *FeatureClientInterface_HasBinding_Call) RunAndReturn(run func() bool) *FeatureClientInterface_HasBinding_Call { + _c.Call.Return(run) + return _c +} + +// HasSubscription provides a mock function with given fields: +func (_m *FeatureClientInterface) HasSubscription() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for HasSubscription") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// FeatureClientInterface_HasSubscription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'HasSubscription' +type FeatureClientInterface_HasSubscription_Call struct { + *mock.Call +} + +// HasSubscription is a helper method to define mock.On call +func (_e *FeatureClientInterface_Expecter) HasSubscription() *FeatureClientInterface_HasSubscription_Call { + return &FeatureClientInterface_HasSubscription_Call{Call: _e.mock.On("HasSubscription")} +} + +func (_c *FeatureClientInterface_HasSubscription_Call) Run(run func()) *FeatureClientInterface_HasSubscription_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *FeatureClientInterface_HasSubscription_Call) Return(_a0 bool) *FeatureClientInterface_HasSubscription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *FeatureClientInterface_HasSubscription_Call) RunAndReturn(run func() bool) *FeatureClientInterface_HasSubscription_Call { + _c.Call.Return(run) + return _c +} + +// Subscribe provides a mock function with given fields: +func (_m *FeatureClientInterface) Subscribe() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for Subscribe") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// FeatureClientInterface_Subscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subscribe' +type FeatureClientInterface_Subscribe_Call struct { + *mock.Call +} + +// Subscribe is a helper method to define mock.On call +func (_e *FeatureClientInterface_Expecter) Subscribe() *FeatureClientInterface_Subscribe_Call { + return &FeatureClientInterface_Subscribe_Call{Call: _e.mock.On("Subscribe")} +} + +func (_c *FeatureClientInterface_Subscribe_Call) Run(run func()) *FeatureClientInterface_Subscribe_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *FeatureClientInterface_Subscribe_Call) Return(_a0 *model.MsgCounterType, _a1 error) *FeatureClientInterface_Subscribe_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *FeatureClientInterface_Subscribe_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *FeatureClientInterface_Subscribe_Call { + _c.Call.Return(run) + return _c +} + +// NewFeatureClientInterface creates a new instance of FeatureClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFeatureClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *FeatureClientInterface { + mock := &FeatureClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/FeatureServerInterface.go b/mocks/FeatureServerInterface.go new file mode 100644 index 00000000..25f32a57 --- /dev/null +++ b/mocks/FeatureServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// FeatureServerInterface is an autogenerated mock type for the FeatureServerInterface type +type FeatureServerInterface struct { + mock.Mock +} + +type FeatureServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *FeatureServerInterface) EXPECT() *FeatureServerInterface_Expecter { + return &FeatureServerInterface_Expecter{mock: &_m.Mock} +} + +// NewFeatureServerInterface creates a new instance of FeatureServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewFeatureServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *FeatureServerInterface { + mock := &FeatureServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IdentificationClientInterface.go b/mocks/IdentificationClientInterface.go new file mode 100644 index 00000000..fe81faa6 --- /dev/null +++ b/mocks/IdentificationClientInterface.go @@ -0,0 +1,92 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// IdentificationClientInterface is an autogenerated mock type for the IdentificationClientInterface type +type IdentificationClientInterface struct { + mock.Mock +} + +type IdentificationClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IdentificationClientInterface) EXPECT() *IdentificationClientInterface_Expecter { + return &IdentificationClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestValues provides a mock function with given fields: +func (_m *IdentificationClientInterface) RequestValues() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestValues") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IdentificationClientInterface_RequestValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestValues' +type IdentificationClientInterface_RequestValues_Call struct { + *mock.Call +} + +// RequestValues is a helper method to define mock.On call +func (_e *IdentificationClientInterface_Expecter) RequestValues() *IdentificationClientInterface_RequestValues_Call { + return &IdentificationClientInterface_RequestValues_Call{Call: _e.mock.On("RequestValues")} +} + +func (_c *IdentificationClientInterface_RequestValues_Call) Run(run func()) *IdentificationClientInterface_RequestValues_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IdentificationClientInterface_RequestValues_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IdentificationClientInterface_RequestValues_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IdentificationClientInterface_RequestValues_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *IdentificationClientInterface_RequestValues_Call { + _c.Call.Return(run) + return _c +} + +// NewIdentificationClientInterface creates a new instance of IdentificationClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIdentificationClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IdentificationClientInterface { + mock := &IdentificationClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IdentificationCommonInterface.go b/mocks/IdentificationCommonInterface.go new file mode 100644 index 00000000..3f708fe0 --- /dev/null +++ b/mocks/IdentificationCommonInterface.go @@ -0,0 +1,139 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// IdentificationCommonInterface is an autogenerated mock type for the IdentificationCommonInterface type +type IdentificationCommonInterface struct { + mock.Mock +} + +type IdentificationCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IdentificationCommonInterface) EXPECT() *IdentificationCommonInterface_Expecter { + return &IdentificationCommonInterface_Expecter{mock: &_m.Mock} +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData +func (_m *IdentificationCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}) bool { + ret := _m.Called(payloadData) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}) bool); ok { + r0 = rf(payloadData) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +func (_e *IdentificationCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { + return &IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData)} +} + +func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{})) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{})) + }) + return _c +} + +func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}) bool) *IdentificationCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDataForFilter provides a mock function with given fields: filter +func (_m *IdentificationCommonInterface) GetDataForFilter(filter model.IdentificationDataType) ([]model.IdentificationDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDataForFilter") + } + + var r0 []model.IdentificationDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.IdentificationDataType) ([]model.IdentificationDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.IdentificationDataType) []model.IdentificationDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.IdentificationDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.IdentificationDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IdentificationCommonInterface_GetDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDataForFilter' +type IdentificationCommonInterface_GetDataForFilter_Call struct { + *mock.Call +} + +// GetDataForFilter is a helper method to define mock.On call +// - filter model.IdentificationDataType +func (_e *IdentificationCommonInterface_Expecter) GetDataForFilter(filter interface{}) *IdentificationCommonInterface_GetDataForFilter_Call { + return &IdentificationCommonInterface_GetDataForFilter_Call{Call: _e.mock.On("GetDataForFilter", filter)} +} + +func (_c *IdentificationCommonInterface_GetDataForFilter_Call) Run(run func(filter model.IdentificationDataType)) *IdentificationCommonInterface_GetDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.IdentificationDataType)) + }) + return _c +} + +func (_c *IdentificationCommonInterface_GetDataForFilter_Call) Return(_a0 []model.IdentificationDataType, _a1 error) *IdentificationCommonInterface_GetDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IdentificationCommonInterface_GetDataForFilter_Call) RunAndReturn(run func(model.IdentificationDataType) ([]model.IdentificationDataType, error)) *IdentificationCommonInterface_GetDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewIdentificationCommonInterface creates a new instance of IdentificationCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIdentificationCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IdentificationCommonInterface { + mock := &IdentificationCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IdentificationServerInterface.go b/mocks/IdentificationServerInterface.go new file mode 100644 index 00000000..e48d9fa6 --- /dev/null +++ b/mocks/IdentificationServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// IdentificationServerInterface is an autogenerated mock type for the IdentificationServerInterface type +type IdentificationServerInterface struct { + mock.Mock +} + +type IdentificationServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IdentificationServerInterface) EXPECT() *IdentificationServerInterface_Expecter { + return &IdentificationServerInterface_Expecter{mock: &_m.Mock} +} + +// NewIdentificationServerInterface creates a new instance of IdentificationServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIdentificationServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IdentificationServerInterface { + mock := &IdentificationServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IncentiveTableClientInterface.go b/mocks/IncentiveTableClientInterface.go new file mode 100644 index 00000000..ba4dd2c9 --- /dev/null +++ b/mocks/IncentiveTableClientInterface.go @@ -0,0 +1,322 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// IncentiveTableClientInterface is an autogenerated mock type for the IncentiveTableClientInterface type +type IncentiveTableClientInterface struct { + mock.Mock +} + +type IncentiveTableClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IncentiveTableClientInterface) EXPECT() *IncentiveTableClientInterface_Expecter { + return &IncentiveTableClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestConstraints provides a mock function with given fields: +func (_m *IncentiveTableClientInterface) RequestConstraints() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestConstraints") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableClientInterface_RequestConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestConstraints' +type IncentiveTableClientInterface_RequestConstraints_Call struct { + *mock.Call +} + +// RequestConstraints is a helper method to define mock.On call +func (_e *IncentiveTableClientInterface_Expecter) RequestConstraints() *IncentiveTableClientInterface_RequestConstraints_Call { + return &IncentiveTableClientInterface_RequestConstraints_Call{Call: _e.mock.On("RequestConstraints")} +} + +func (_c *IncentiveTableClientInterface_RequestConstraints_Call) Run(run func()) *IncentiveTableClientInterface_RequestConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestConstraints_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IncentiveTableClientInterface_RequestConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestConstraints_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *IncentiveTableClientInterface_RequestConstraints_Call { + _c.Call.Return(run) + return _c +} + +// RequestDescriptions provides a mock function with given fields: +func (_m *IncentiveTableClientInterface) RequestDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableClientInterface_RequestDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestDescriptions' +type IncentiveTableClientInterface_RequestDescriptions_Call struct { + *mock.Call +} + +// RequestDescriptions is a helper method to define mock.On call +func (_e *IncentiveTableClientInterface_Expecter) RequestDescriptions() *IncentiveTableClientInterface_RequestDescriptions_Call { + return &IncentiveTableClientInterface_RequestDescriptions_Call{Call: _e.mock.On("RequestDescriptions")} +} + +func (_c *IncentiveTableClientInterface_RequestDescriptions_Call) Run(run func()) *IncentiveTableClientInterface_RequestDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IncentiveTableClientInterface_RequestDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *IncentiveTableClientInterface_RequestDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// RequestValues provides a mock function with given fields: +func (_m *IncentiveTableClientInterface) RequestValues() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestValues") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableClientInterface_RequestValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestValues' +type IncentiveTableClientInterface_RequestValues_Call struct { + *mock.Call +} + +// RequestValues is a helper method to define mock.On call +func (_e *IncentiveTableClientInterface_Expecter) RequestValues() *IncentiveTableClientInterface_RequestValues_Call { + return &IncentiveTableClientInterface_RequestValues_Call{Call: _e.mock.On("RequestValues")} +} + +func (_c *IncentiveTableClientInterface_RequestValues_Call) Run(run func()) *IncentiveTableClientInterface_RequestValues_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestValues_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IncentiveTableClientInterface_RequestValues_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableClientInterface_RequestValues_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *IncentiveTableClientInterface_RequestValues_Call { + _c.Call.Return(run) + return _c +} + +// WriteDescriptions provides a mock function with given fields: data +func (_m *IncentiveTableClientInterface) WriteDescriptions(data []model.IncentiveTableDescriptionType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func([]model.IncentiveTableDescriptionType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func([]model.IncentiveTableDescriptionType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func([]model.IncentiveTableDescriptionType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableClientInterface_WriteDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteDescriptions' +type IncentiveTableClientInterface_WriteDescriptions_Call struct { + *mock.Call +} + +// WriteDescriptions is a helper method to define mock.On call +// - data []model.IncentiveTableDescriptionType +func (_e *IncentiveTableClientInterface_Expecter) WriteDescriptions(data interface{}) *IncentiveTableClientInterface_WriteDescriptions_Call { + return &IncentiveTableClientInterface_WriteDescriptions_Call{Call: _e.mock.On("WriteDescriptions", data)} +} + +func (_c *IncentiveTableClientInterface_WriteDescriptions_Call) Run(run func(data []model.IncentiveTableDescriptionType)) *IncentiveTableClientInterface_WriteDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]model.IncentiveTableDescriptionType)) + }) + return _c +} + +func (_c *IncentiveTableClientInterface_WriteDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IncentiveTableClientInterface_WriteDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableClientInterface_WriteDescriptions_Call) RunAndReturn(run func([]model.IncentiveTableDescriptionType) (*model.MsgCounterType, error)) *IncentiveTableClientInterface_WriteDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// WriteValues provides a mock function with given fields: data +func (_m *IncentiveTableClientInterface) WriteValues(data []model.IncentiveTableType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteValues") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func([]model.IncentiveTableType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func([]model.IncentiveTableType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func([]model.IncentiveTableType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableClientInterface_WriteValues_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteValues' +type IncentiveTableClientInterface_WriteValues_Call struct { + *mock.Call +} + +// WriteValues is a helper method to define mock.On call +// - data []model.IncentiveTableType +func (_e *IncentiveTableClientInterface_Expecter) WriteValues(data interface{}) *IncentiveTableClientInterface_WriteValues_Call { + return &IncentiveTableClientInterface_WriteValues_Call{Call: _e.mock.On("WriteValues", data)} +} + +func (_c *IncentiveTableClientInterface_WriteValues_Call) Run(run func(data []model.IncentiveTableType)) *IncentiveTableClientInterface_WriteValues_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]model.IncentiveTableType)) + }) + return _c +} + +func (_c *IncentiveTableClientInterface_WriteValues_Call) Return(_a0 *model.MsgCounterType, _a1 error) *IncentiveTableClientInterface_WriteValues_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableClientInterface_WriteValues_Call) RunAndReturn(run func([]model.IncentiveTableType) (*model.MsgCounterType, error)) *IncentiveTableClientInterface_WriteValues_Call { + _c.Call.Return(run) + return _c +} + +// NewIncentiveTableClientInterface creates a new instance of IncentiveTableClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIncentiveTableClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IncentiveTableClientInterface { + mock := &IncentiveTableClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IncentiveTableCommonInterface.go b/mocks/IncentiveTableCommonInterface.go new file mode 100644 index 00000000..beff21e3 --- /dev/null +++ b/mocks/IncentiveTableCommonInterface.go @@ -0,0 +1,207 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// IncentiveTableCommonInterface is an autogenerated mock type for the IncentiveTableCommonInterface type +type IncentiveTableCommonInterface struct { + mock.Mock +} + +type IncentiveTableCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IncentiveTableCommonInterface) EXPECT() *IncentiveTableCommonInterface_Expecter { + return &IncentiveTableCommonInterface_Expecter{mock: &_m.Mock} +} + +// GetConstraints provides a mock function with given fields: +func (_m *IncentiveTableCommonInterface) GetConstraints() ([]model.IncentiveTableConstraintsType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetConstraints") + } + + var r0 []model.IncentiveTableConstraintsType + var r1 error + if rf, ok := ret.Get(0).(func() ([]model.IncentiveTableConstraintsType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []model.IncentiveTableConstraintsType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.IncentiveTableConstraintsType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableCommonInterface_GetConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConstraints' +type IncentiveTableCommonInterface_GetConstraints_Call struct { + *mock.Call +} + +// GetConstraints is a helper method to define mock.On call +func (_e *IncentiveTableCommonInterface_Expecter) GetConstraints() *IncentiveTableCommonInterface_GetConstraints_Call { + return &IncentiveTableCommonInterface_GetConstraints_Call{Call: _e.mock.On("GetConstraints")} +} + +func (_c *IncentiveTableCommonInterface_GetConstraints_Call) Run(run func()) *IncentiveTableCommonInterface_GetConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetConstraints_Call) Return(_a0 []model.IncentiveTableConstraintsType, _a1 error) *IncentiveTableCommonInterface_GetConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetConstraints_Call) RunAndReturn(run func() ([]model.IncentiveTableConstraintsType, error)) *IncentiveTableCommonInterface_GetConstraints_Call { + _c.Call.Return(run) + return _c +} + +// GetData provides a mock function with given fields: +func (_m *IncentiveTableCommonInterface) GetData() ([]model.IncentiveTableType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetData") + } + + var r0 []model.IncentiveTableType + var r1 error + if rf, ok := ret.Get(0).(func() ([]model.IncentiveTableType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []model.IncentiveTableType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.IncentiveTableType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableCommonInterface_GetData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetData' +type IncentiveTableCommonInterface_GetData_Call struct { + *mock.Call +} + +// GetData is a helper method to define mock.On call +func (_e *IncentiveTableCommonInterface_Expecter) GetData() *IncentiveTableCommonInterface_GetData_Call { + return &IncentiveTableCommonInterface_GetData_Call{Call: _e.mock.On("GetData")} +} + +func (_c *IncentiveTableCommonInterface_GetData_Call) Run(run func()) *IncentiveTableCommonInterface_GetData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetData_Call) Return(_a0 []model.IncentiveTableType, _a1 error) *IncentiveTableCommonInterface_GetData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetData_Call) RunAndReturn(run func() ([]model.IncentiveTableType, error)) *IncentiveTableCommonInterface_GetData_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionsForFilter provides a mock function with given fields: filter +func (_m *IncentiveTableCommonInterface) GetDescriptionsForFilter(filter model.TariffDescriptionDataType) ([]model.IncentiveTableDescriptionType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionsForFilter") + } + + var r0 []model.IncentiveTableDescriptionType + var r1 error + if rf, ok := ret.Get(0).(func(model.TariffDescriptionDataType) ([]model.IncentiveTableDescriptionType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.TariffDescriptionDataType) []model.IncentiveTableDescriptionType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.IncentiveTableDescriptionType) + } + } + + if rf, ok := ret.Get(1).(func(model.TariffDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// IncentiveTableCommonInterface_GetDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionsForFilter' +type IncentiveTableCommonInterface_GetDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetDescriptionsForFilter is a helper method to define mock.On call +// - filter model.TariffDescriptionDataType +func (_e *IncentiveTableCommonInterface_Expecter) GetDescriptionsForFilter(filter interface{}) *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call { + return &IncentiveTableCommonInterface_GetDescriptionsForFilter_Call{Call: _e.mock.On("GetDescriptionsForFilter", filter)} +} + +func (_c *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call) Run(run func(filter model.TariffDescriptionDataType)) *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.TariffDescriptionDataType)) + }) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call) Return(_a0 []model.IncentiveTableDescriptionType, _a1 error) *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call) RunAndReturn(run func(model.TariffDescriptionDataType) ([]model.IncentiveTableDescriptionType, error)) *IncentiveTableCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewIncentiveTableCommonInterface creates a new instance of IncentiveTableCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIncentiveTableCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IncentiveTableCommonInterface { + mock := &IncentiveTableCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/IncentiveTableServerInterface.go b/mocks/IncentiveTableServerInterface.go new file mode 100644 index 00000000..5280feaf --- /dev/null +++ b/mocks/IncentiveTableServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// IncentiveTableServerInterface is an autogenerated mock type for the IncentiveTableServerInterface type +type IncentiveTableServerInterface struct { + mock.Mock +} + +type IncentiveTableServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *IncentiveTableServerInterface) EXPECT() *IncentiveTableServerInterface_Expecter { + return &IncentiveTableServerInterface_Expecter{mock: &_m.Mock} +} + +// NewIncentiveTableServerInterface creates a new instance of IncentiveTableServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewIncentiveTableServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *IncentiveTableServerInterface { + mock := &IncentiveTableServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/LoadControlClientInterface.go b/mocks/LoadControlClientInterface.go new file mode 100644 index 00000000..ecc7b4e8 --- /dev/null +++ b/mocks/LoadControlClientInterface.go @@ -0,0 +1,264 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// LoadControlClientInterface is an autogenerated mock type for the LoadControlClientInterface type +type LoadControlClientInterface struct { + mock.Mock +} + +type LoadControlClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *LoadControlClientInterface) EXPECT() *LoadControlClientInterface_Expecter { + return &LoadControlClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestLimitConstraints provides a mock function with given fields: +func (_m *LoadControlClientInterface) RequestLimitConstraints() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestLimitConstraints") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlClientInterface_RequestLimitConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestLimitConstraints' +type LoadControlClientInterface_RequestLimitConstraints_Call struct { + *mock.Call +} + +// RequestLimitConstraints is a helper method to define mock.On call +func (_e *LoadControlClientInterface_Expecter) RequestLimitConstraints() *LoadControlClientInterface_RequestLimitConstraints_Call { + return &LoadControlClientInterface_RequestLimitConstraints_Call{Call: _e.mock.On("RequestLimitConstraints")} +} + +func (_c *LoadControlClientInterface_RequestLimitConstraints_Call) Run(run func()) *LoadControlClientInterface_RequestLimitConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitConstraints_Call) Return(_a0 *model.MsgCounterType, _a1 error) *LoadControlClientInterface_RequestLimitConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitConstraints_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *LoadControlClientInterface_RequestLimitConstraints_Call { + _c.Call.Return(run) + return _c +} + +// RequestLimitData provides a mock function with given fields: +func (_m *LoadControlClientInterface) RequestLimitData() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestLimitData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlClientInterface_RequestLimitData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestLimitData' +type LoadControlClientInterface_RequestLimitData_Call struct { + *mock.Call +} + +// RequestLimitData is a helper method to define mock.On call +func (_e *LoadControlClientInterface_Expecter) RequestLimitData() *LoadControlClientInterface_RequestLimitData_Call { + return &LoadControlClientInterface_RequestLimitData_Call{Call: _e.mock.On("RequestLimitData")} +} + +func (_c *LoadControlClientInterface_RequestLimitData_Call) Run(run func()) *LoadControlClientInterface_RequestLimitData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *LoadControlClientInterface_RequestLimitData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitData_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *LoadControlClientInterface_RequestLimitData_Call { + _c.Call.Return(run) + return _c +} + +// RequestLimitDescriptions provides a mock function with given fields: +func (_m *LoadControlClientInterface) RequestLimitDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestLimitDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlClientInterface_RequestLimitDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestLimitDescriptions' +type LoadControlClientInterface_RequestLimitDescriptions_Call struct { + *mock.Call +} + +// RequestLimitDescriptions is a helper method to define mock.On call +func (_e *LoadControlClientInterface_Expecter) RequestLimitDescriptions() *LoadControlClientInterface_RequestLimitDescriptions_Call { + return &LoadControlClientInterface_RequestLimitDescriptions_Call{Call: _e.mock.On("RequestLimitDescriptions")} +} + +func (_c *LoadControlClientInterface_RequestLimitDescriptions_Call) Run(run func()) *LoadControlClientInterface_RequestLimitDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *LoadControlClientInterface_RequestLimitDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlClientInterface_RequestLimitDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *LoadControlClientInterface_RequestLimitDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// WriteLimitData provides a mock function with given fields: data +func (_m *LoadControlClientInterface) WriteLimitData(data []model.LoadControlLimitDataType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteLimitData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func([]model.LoadControlLimitDataType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func([]model.LoadControlLimitDataType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func([]model.LoadControlLimitDataType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlClientInterface_WriteLimitData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteLimitData' +type LoadControlClientInterface_WriteLimitData_Call struct { + *mock.Call +} + +// WriteLimitData is a helper method to define mock.On call +// - data []model.LoadControlLimitDataType +func (_e *LoadControlClientInterface_Expecter) WriteLimitData(data interface{}) *LoadControlClientInterface_WriteLimitData_Call { + return &LoadControlClientInterface_WriteLimitData_Call{Call: _e.mock.On("WriteLimitData", data)} +} + +func (_c *LoadControlClientInterface_WriteLimitData_Call) Run(run func(data []model.LoadControlLimitDataType)) *LoadControlClientInterface_WriteLimitData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]model.LoadControlLimitDataType)) + }) + return _c +} + +func (_c *LoadControlClientInterface_WriteLimitData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *LoadControlClientInterface_WriteLimitData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlClientInterface_WriteLimitData_Call) RunAndReturn(run func([]model.LoadControlLimitDataType) (*model.MsgCounterType, error)) *LoadControlClientInterface_WriteLimitData_Call { + _c.Call.Return(run) + return _c +} + +// NewLoadControlClientInterface creates a new instance of LoadControlClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLoadControlClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *LoadControlClientInterface { + mock := &LoadControlClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/LoadControlCommonInterface.go b/mocks/LoadControlCommonInterface.go new file mode 100644 index 00000000..7d906640 --- /dev/null +++ b/mocks/LoadControlCommonInterface.go @@ -0,0 +1,314 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// LoadControlCommonInterface is an autogenerated mock type for the LoadControlCommonInterface type +type LoadControlCommonInterface struct { + mock.Mock +} + +type LoadControlCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *LoadControlCommonInterface) EXPECT() *LoadControlCommonInterface_Expecter { + return &LoadControlCommonInterface_Expecter{mock: &_m.Mock} +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *LoadControlCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *LoadControlCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { + return &LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *LoadControlCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetLimitDataForFilter provides a mock function with given fields: filter +func (_m *LoadControlCommonInterface) GetLimitDataForFilter(filter model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetLimitDataForFilter") + } + + var r0 []model.LoadControlLimitDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDescriptionDataType) []model.LoadControlLimitDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.LoadControlLimitDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.LoadControlLimitDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlCommonInterface_GetLimitDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLimitDataForFilter' +type LoadControlCommonInterface_GetLimitDataForFilter_Call struct { + *mock.Call +} + +// GetLimitDataForFilter is a helper method to define mock.On call +// - filter model.LoadControlLimitDescriptionDataType +func (_e *LoadControlCommonInterface_Expecter) GetLimitDataForFilter(filter interface{}) *LoadControlCommonInterface_GetLimitDataForFilter_Call { + return &LoadControlCommonInterface_GetLimitDataForFilter_Call{Call: _e.mock.On("GetLimitDataForFilter", filter)} +} + +func (_c *LoadControlCommonInterface_GetLimitDataForFilter_Call) Run(run func(filter model.LoadControlLimitDescriptionDataType)) *LoadControlCommonInterface_GetLimitDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitDescriptionDataType)) + }) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDataForFilter_Call) Return(_a0 []model.LoadControlLimitDataType, _a1 error) *LoadControlCommonInterface_GetLimitDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDataForFilter_Call) RunAndReturn(run func(model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDataType, error)) *LoadControlCommonInterface_GetLimitDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetLimitDataForId provides a mock function with given fields: limitId +func (_m *LoadControlCommonInterface) GetLimitDataForId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error) { + ret := _m.Called(limitId) + + if len(ret) == 0 { + panic("no return value specified for GetLimitDataForId") + } + + var r0 *model.LoadControlLimitDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error)); ok { + return rf(limitId) + } + if rf, ok := ret.Get(0).(func(model.LoadControlLimitIdType) *model.LoadControlLimitDataType); ok { + r0 = rf(limitId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.LoadControlLimitDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.LoadControlLimitIdType) error); ok { + r1 = rf(limitId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlCommonInterface_GetLimitDataForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLimitDataForId' +type LoadControlCommonInterface_GetLimitDataForId_Call struct { + *mock.Call +} + +// GetLimitDataForId is a helper method to define mock.On call +// - limitId model.LoadControlLimitIdType +func (_e *LoadControlCommonInterface_Expecter) GetLimitDataForId(limitId interface{}) *LoadControlCommonInterface_GetLimitDataForId_Call { + return &LoadControlCommonInterface_GetLimitDataForId_Call{Call: _e.mock.On("GetLimitDataForId", limitId)} +} + +func (_c *LoadControlCommonInterface_GetLimitDataForId_Call) Run(run func(limitId model.LoadControlLimitIdType)) *LoadControlCommonInterface_GetLimitDataForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitIdType)) + }) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDataForId_Call) Return(_a0 *model.LoadControlLimitDataType, _a1 error) *LoadControlCommonInterface_GetLimitDataForId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDataForId_Call) RunAndReturn(run func(model.LoadControlLimitIdType) (*model.LoadControlLimitDataType, error)) *LoadControlCommonInterface_GetLimitDataForId_Call { + _c.Call.Return(run) + return _c +} + +// GetLimitDescriptionForId provides a mock function with given fields: limitId +func (_m *LoadControlCommonInterface) GetLimitDescriptionForId(limitId model.LoadControlLimitIdType) (*model.LoadControlLimitDescriptionDataType, error) { + ret := _m.Called(limitId) + + if len(ret) == 0 { + panic("no return value specified for GetLimitDescriptionForId") + } + + var r0 *model.LoadControlLimitDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitIdType) (*model.LoadControlLimitDescriptionDataType, error)); ok { + return rf(limitId) + } + if rf, ok := ret.Get(0).(func(model.LoadControlLimitIdType) *model.LoadControlLimitDescriptionDataType); ok { + r0 = rf(limitId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.LoadControlLimitDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.LoadControlLimitIdType) error); ok { + r1 = rf(limitId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlCommonInterface_GetLimitDescriptionForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLimitDescriptionForId' +type LoadControlCommonInterface_GetLimitDescriptionForId_Call struct { + *mock.Call +} + +// GetLimitDescriptionForId is a helper method to define mock.On call +// - limitId model.LoadControlLimitIdType +func (_e *LoadControlCommonInterface_Expecter) GetLimitDescriptionForId(limitId interface{}) *LoadControlCommonInterface_GetLimitDescriptionForId_Call { + return &LoadControlCommonInterface_GetLimitDescriptionForId_Call{Call: _e.mock.On("GetLimitDescriptionForId", limitId)} +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionForId_Call) Run(run func(limitId model.LoadControlLimitIdType)) *LoadControlCommonInterface_GetLimitDescriptionForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitIdType)) + }) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionForId_Call) Return(_a0 *model.LoadControlLimitDescriptionDataType, _a1 error) *LoadControlCommonInterface_GetLimitDescriptionForId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionForId_Call) RunAndReturn(run func(model.LoadControlLimitIdType) (*model.LoadControlLimitDescriptionDataType, error)) *LoadControlCommonInterface_GetLimitDescriptionForId_Call { + _c.Call.Return(run) + return _c +} + +// GetLimitDescriptionsForFilter provides a mock function with given fields: filter +func (_m *LoadControlCommonInterface) GetLimitDescriptionsForFilter(filter model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetLimitDescriptionsForFilter") + } + + var r0 []model.LoadControlLimitDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDescriptionDataType) []model.LoadControlLimitDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.LoadControlLimitDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.LoadControlLimitDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetLimitDescriptionsForFilter' +type LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetLimitDescriptionsForFilter is a helper method to define mock.On call +// - filter model.LoadControlLimitDescriptionDataType +func (_e *LoadControlCommonInterface_Expecter) GetLimitDescriptionsForFilter(filter interface{}) *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call { + return &LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call{Call: _e.mock.On("GetLimitDescriptionsForFilter", filter)} +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call) Run(run func(filter model.LoadControlLimitDescriptionDataType)) *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitDescriptionDataType)) + }) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call) Return(_a0 []model.LoadControlLimitDescriptionDataType, _a1 error) *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call) RunAndReturn(run func(model.LoadControlLimitDescriptionDataType) ([]model.LoadControlLimitDescriptionDataType, error)) *LoadControlCommonInterface_GetLimitDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewLoadControlCommonInterface creates a new instance of LoadControlCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLoadControlCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *LoadControlCommonInterface { + mock := &LoadControlCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/LoadControlServerInterface.go b/mocks/LoadControlServerInterface.go new file mode 100644 index 00000000..cdefd5f6 --- /dev/null +++ b/mocks/LoadControlServerInterface.go @@ -0,0 +1,179 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// LoadControlServerInterface is an autogenerated mock type for the LoadControlServerInterface type +type LoadControlServerInterface struct { + mock.Mock +} + +type LoadControlServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *LoadControlServerInterface) EXPECT() *LoadControlServerInterface_Expecter { + return &LoadControlServerInterface_Expecter{mock: &_m.Mock} +} + +// AddLimitDescription provides a mock function with given fields: description +func (_m *LoadControlServerInterface) AddLimitDescription(description model.LoadControlLimitDescriptionDataType) *model.LoadControlLimitIdType { + ret := _m.Called(description) + + if len(ret) == 0 { + panic("no return value specified for AddLimitDescription") + } + + var r0 *model.LoadControlLimitIdType + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDescriptionDataType) *model.LoadControlLimitIdType); ok { + r0 = rf(description) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.LoadControlLimitIdType) + } + } + + return r0 +} + +// LoadControlServerInterface_AddLimitDescription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddLimitDescription' +type LoadControlServerInterface_AddLimitDescription_Call struct { + *mock.Call +} + +// AddLimitDescription is a helper method to define mock.On call +// - description model.LoadControlLimitDescriptionDataType +func (_e *LoadControlServerInterface_Expecter) AddLimitDescription(description interface{}) *LoadControlServerInterface_AddLimitDescription_Call { + return &LoadControlServerInterface_AddLimitDescription_Call{Call: _e.mock.On("AddLimitDescription", description)} +} + +func (_c *LoadControlServerInterface_AddLimitDescription_Call) Run(run func(description model.LoadControlLimitDescriptionDataType)) *LoadControlServerInterface_AddLimitDescription_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitDescriptionDataType)) + }) + return _c +} + +func (_c *LoadControlServerInterface_AddLimitDescription_Call) Return(_a0 *model.LoadControlLimitIdType) *LoadControlServerInterface_AddLimitDescription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *LoadControlServerInterface_AddLimitDescription_Call) RunAndReturn(run func(model.LoadControlLimitDescriptionDataType) *model.LoadControlLimitIdType) *LoadControlServerInterface_AddLimitDescription_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLimitDataForFilter provides a mock function with given fields: data, deleteElements, filter +func (_m *LoadControlServerInterface) UpdateLimitDataForFilter(data model.LoadControlLimitDataType, deleteElements *model.LoadControlLimitDataElementsType, filter model.LoadControlLimitDescriptionDataType) error { + ret := _m.Called(data, deleteElements, filter) + + if len(ret) == 0 { + panic("no return value specified for UpdateLimitDataForFilter") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDataType, *model.LoadControlLimitDataElementsType, model.LoadControlLimitDescriptionDataType) error); ok { + r0 = rf(data, deleteElements, filter) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// LoadControlServerInterface_UpdateLimitDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLimitDataForFilter' +type LoadControlServerInterface_UpdateLimitDataForFilter_Call struct { + *mock.Call +} + +// UpdateLimitDataForFilter is a helper method to define mock.On call +// - data model.LoadControlLimitDataType +// - deleteElements *model.LoadControlLimitDataElementsType +// - filter model.LoadControlLimitDescriptionDataType +func (_e *LoadControlServerInterface_Expecter) UpdateLimitDataForFilter(data interface{}, deleteElements interface{}, filter interface{}) *LoadControlServerInterface_UpdateLimitDataForFilter_Call { + return &LoadControlServerInterface_UpdateLimitDataForFilter_Call{Call: _e.mock.On("UpdateLimitDataForFilter", data, deleteElements, filter)} +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForFilter_Call) Run(run func(data model.LoadControlLimitDataType, deleteElements *model.LoadControlLimitDataElementsType, filter model.LoadControlLimitDescriptionDataType)) *LoadControlServerInterface_UpdateLimitDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitDataType), args[1].(*model.LoadControlLimitDataElementsType), args[2].(model.LoadControlLimitDescriptionDataType)) + }) + return _c +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForFilter_Call) Return(_a0 error) *LoadControlServerInterface_UpdateLimitDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForFilter_Call) RunAndReturn(run func(model.LoadControlLimitDataType, *model.LoadControlLimitDataElementsType, model.LoadControlLimitDescriptionDataType) error) *LoadControlServerInterface_UpdateLimitDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// UpdateLimitDataForId provides a mock function with given fields: data, deleteElements, limitId +func (_m *LoadControlServerInterface) UpdateLimitDataForId(data model.LoadControlLimitDataType, deleteElements *model.LoadControlLimitDataElementsType, limitId model.LoadControlLimitIdType) error { + ret := _m.Called(data, deleteElements, limitId) + + if len(ret) == 0 { + panic("no return value specified for UpdateLimitDataForId") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.LoadControlLimitDataType, *model.LoadControlLimitDataElementsType, model.LoadControlLimitIdType) error); ok { + r0 = rf(data, deleteElements, limitId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// LoadControlServerInterface_UpdateLimitDataForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateLimitDataForId' +type LoadControlServerInterface_UpdateLimitDataForId_Call struct { + *mock.Call +} + +// UpdateLimitDataForId is a helper method to define mock.On call +// - data model.LoadControlLimitDataType +// - deleteElements *model.LoadControlLimitDataElementsType +// - limitId model.LoadControlLimitIdType +func (_e *LoadControlServerInterface_Expecter) UpdateLimitDataForId(data interface{}, deleteElements interface{}, limitId interface{}) *LoadControlServerInterface_UpdateLimitDataForId_Call { + return &LoadControlServerInterface_UpdateLimitDataForId_Call{Call: _e.mock.On("UpdateLimitDataForId", data, deleteElements, limitId)} +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForId_Call) Run(run func(data model.LoadControlLimitDataType, deleteElements *model.LoadControlLimitDataElementsType, limitId model.LoadControlLimitIdType)) *LoadControlServerInterface_UpdateLimitDataForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.LoadControlLimitDataType), args[1].(*model.LoadControlLimitDataElementsType), args[2].(model.LoadControlLimitIdType)) + }) + return _c +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForId_Call) Return(_a0 error) *LoadControlServerInterface_UpdateLimitDataForId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *LoadControlServerInterface_UpdateLimitDataForId_Call) RunAndReturn(run func(model.LoadControlLimitDataType, *model.LoadControlLimitDataElementsType, model.LoadControlLimitIdType) error) *LoadControlServerInterface_UpdateLimitDataForId_Call { + _c.Call.Return(run) + return _c +} + +// NewLoadControlServerInterface creates a new instance of LoadControlServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewLoadControlServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *LoadControlServerInterface { + mock := &LoadControlServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/MeasurementClientInterface.go b/mocks/MeasurementClientInterface.go new file mode 100644 index 00000000..7d923fcd --- /dev/null +++ b/mocks/MeasurementClientInterface.go @@ -0,0 +1,206 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// MeasurementClientInterface is an autogenerated mock type for the MeasurementClientInterface type +type MeasurementClientInterface struct { + mock.Mock +} + +type MeasurementClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *MeasurementClientInterface) EXPECT() *MeasurementClientInterface_Expecter { + return &MeasurementClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestConstraints provides a mock function with given fields: +func (_m *MeasurementClientInterface) RequestConstraints() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestConstraints") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementClientInterface_RequestConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestConstraints' +type MeasurementClientInterface_RequestConstraints_Call struct { + *mock.Call +} + +// RequestConstraints is a helper method to define mock.On call +func (_e *MeasurementClientInterface_Expecter) RequestConstraints() *MeasurementClientInterface_RequestConstraints_Call { + return &MeasurementClientInterface_RequestConstraints_Call{Call: _e.mock.On("RequestConstraints")} +} + +func (_c *MeasurementClientInterface_RequestConstraints_Call) Run(run func()) *MeasurementClientInterface_RequestConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MeasurementClientInterface_RequestConstraints_Call) Return(_a0 *model.MsgCounterType, _a1 error) *MeasurementClientInterface_RequestConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementClientInterface_RequestConstraints_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *MeasurementClientInterface_RequestConstraints_Call { + _c.Call.Return(run) + return _c +} + +// RequestData provides a mock function with given fields: +func (_m *MeasurementClientInterface) RequestData() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementClientInterface_RequestData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestData' +type MeasurementClientInterface_RequestData_Call struct { + *mock.Call +} + +// RequestData is a helper method to define mock.On call +func (_e *MeasurementClientInterface_Expecter) RequestData() *MeasurementClientInterface_RequestData_Call { + return &MeasurementClientInterface_RequestData_Call{Call: _e.mock.On("RequestData")} +} + +func (_c *MeasurementClientInterface_RequestData_Call) Run(run func()) *MeasurementClientInterface_RequestData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MeasurementClientInterface_RequestData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *MeasurementClientInterface_RequestData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementClientInterface_RequestData_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *MeasurementClientInterface_RequestData_Call { + _c.Call.Return(run) + return _c +} + +// RequestDescriptions provides a mock function with given fields: +func (_m *MeasurementClientInterface) RequestDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementClientInterface_RequestDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestDescriptions' +type MeasurementClientInterface_RequestDescriptions_Call struct { + *mock.Call +} + +// RequestDescriptions is a helper method to define mock.On call +func (_e *MeasurementClientInterface_Expecter) RequestDescriptions() *MeasurementClientInterface_RequestDescriptions_Call { + return &MeasurementClientInterface_RequestDescriptions_Call{Call: _e.mock.On("RequestDescriptions")} +} + +func (_c *MeasurementClientInterface_RequestDescriptions_Call) Run(run func()) *MeasurementClientInterface_RequestDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *MeasurementClientInterface_RequestDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *MeasurementClientInterface_RequestDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementClientInterface_RequestDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *MeasurementClientInterface_RequestDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// NewMeasurementClientInterface creates a new instance of MeasurementClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMeasurementClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *MeasurementClientInterface { + mock := &MeasurementClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/MeasurementCommonInterface.go b/mocks/MeasurementCommonInterface.go new file mode 100644 index 00000000..0885cff2 --- /dev/null +++ b/mocks/MeasurementCommonInterface.go @@ -0,0 +1,372 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// MeasurementCommonInterface is an autogenerated mock type for the MeasurementCommonInterface type +type MeasurementCommonInterface struct { + mock.Mock +} + +type MeasurementCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *MeasurementCommonInterface) EXPECT() *MeasurementCommonInterface_Expecter { + return &MeasurementCommonInterface_Expecter{mock: &_m.Mock} +} + +// CheckEventPayloadDataForFilter provides a mock function with given fields: payloadData, filter +func (_m *MeasurementCommonInterface) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) bool { + ret := _m.Called(payloadData, filter) + + if len(ret) == 0 { + panic("no return value specified for CheckEventPayloadDataForFilter") + } + + var r0 bool + if rf, ok := ret.Get(0).(func(interface{}, interface{}) bool); ok { + r0 = rf(payloadData, filter) + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CheckEventPayloadDataForFilter' +type MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call struct { + *mock.Call +} + +// CheckEventPayloadDataForFilter is a helper method to define mock.On call +// - payloadData interface{} +// - filter interface{} +func (_e *MeasurementCommonInterface_Expecter) CheckEventPayloadDataForFilter(payloadData interface{}, filter interface{}) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { + return &MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call{Call: _e.mock.On("CheckEventPayloadDataForFilter", payloadData, filter)} +} + +func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) Run(run func(payloadData interface{}, filter interface{})) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(interface{}), args[1].(interface{})) + }) + return _c +} + +func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) Return(_a0 bool) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call) RunAndReturn(run func(interface{}, interface{}) bool) *MeasurementCommonInterface_CheckEventPayloadDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetConstraintsForFilter provides a mock function with given fields: filter +func (_m *MeasurementCommonInterface) GetConstraintsForFilter(filter model.MeasurementConstraintsDataType) ([]model.MeasurementConstraintsDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetConstraintsForFilter") + } + + var r0 []model.MeasurementConstraintsDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.MeasurementConstraintsDataType) ([]model.MeasurementConstraintsDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.MeasurementConstraintsDataType) []model.MeasurementConstraintsDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.MeasurementConstraintsDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.MeasurementConstraintsDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementCommonInterface_GetConstraintsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConstraintsForFilter' +type MeasurementCommonInterface_GetConstraintsForFilter_Call struct { + *mock.Call +} + +// GetConstraintsForFilter is a helper method to define mock.On call +// - filter model.MeasurementConstraintsDataType +func (_e *MeasurementCommonInterface_Expecter) GetConstraintsForFilter(filter interface{}) *MeasurementCommonInterface_GetConstraintsForFilter_Call { + return &MeasurementCommonInterface_GetConstraintsForFilter_Call{Call: _e.mock.On("GetConstraintsForFilter", filter)} +} + +func (_c *MeasurementCommonInterface_GetConstraintsForFilter_Call) Run(run func(filter model.MeasurementConstraintsDataType)) *MeasurementCommonInterface_GetConstraintsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementConstraintsDataType)) + }) + return _c +} + +func (_c *MeasurementCommonInterface_GetConstraintsForFilter_Call) Return(_a0 []model.MeasurementConstraintsDataType, _a1 error) *MeasurementCommonInterface_GetConstraintsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementCommonInterface_GetConstraintsForFilter_Call) RunAndReturn(run func(model.MeasurementConstraintsDataType) ([]model.MeasurementConstraintsDataType, error)) *MeasurementCommonInterface_GetConstraintsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDataForFilter provides a mock function with given fields: filter +func (_m *MeasurementCommonInterface) GetDataForFilter(filter model.MeasurementDescriptionDataType) ([]model.MeasurementDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDataForFilter") + } + + var r0 []model.MeasurementDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.MeasurementDescriptionDataType) ([]model.MeasurementDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.MeasurementDescriptionDataType) []model.MeasurementDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.MeasurementDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.MeasurementDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementCommonInterface_GetDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDataForFilter' +type MeasurementCommonInterface_GetDataForFilter_Call struct { + *mock.Call +} + +// GetDataForFilter is a helper method to define mock.On call +// - filter model.MeasurementDescriptionDataType +func (_e *MeasurementCommonInterface_Expecter) GetDataForFilter(filter interface{}) *MeasurementCommonInterface_GetDataForFilter_Call { + return &MeasurementCommonInterface_GetDataForFilter_Call{Call: _e.mock.On("GetDataForFilter", filter)} +} + +func (_c *MeasurementCommonInterface_GetDataForFilter_Call) Run(run func(filter model.MeasurementDescriptionDataType)) *MeasurementCommonInterface_GetDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementDescriptionDataType)) + }) + return _c +} + +func (_c *MeasurementCommonInterface_GetDataForFilter_Call) Return(_a0 []model.MeasurementDataType, _a1 error) *MeasurementCommonInterface_GetDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementCommonInterface_GetDataForFilter_Call) RunAndReturn(run func(model.MeasurementDescriptionDataType) ([]model.MeasurementDataType, error)) *MeasurementCommonInterface_GetDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDataForId provides a mock function with given fields: measurementId +func (_m *MeasurementCommonInterface) GetDataForId(measurementId model.MeasurementIdType) (*model.MeasurementDataType, error) { + ret := _m.Called(measurementId) + + if len(ret) == 0 { + panic("no return value specified for GetDataForId") + } + + var r0 *model.MeasurementDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.MeasurementIdType) (*model.MeasurementDataType, error)); ok { + return rf(measurementId) + } + if rf, ok := ret.Get(0).(func(model.MeasurementIdType) *model.MeasurementDataType); ok { + r0 = rf(measurementId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MeasurementDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.MeasurementIdType) error); ok { + r1 = rf(measurementId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementCommonInterface_GetDataForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDataForId' +type MeasurementCommonInterface_GetDataForId_Call struct { + *mock.Call +} + +// GetDataForId is a helper method to define mock.On call +// - measurementId model.MeasurementIdType +func (_e *MeasurementCommonInterface_Expecter) GetDataForId(measurementId interface{}) *MeasurementCommonInterface_GetDataForId_Call { + return &MeasurementCommonInterface_GetDataForId_Call{Call: _e.mock.On("GetDataForId", measurementId)} +} + +func (_c *MeasurementCommonInterface_GetDataForId_Call) Run(run func(measurementId model.MeasurementIdType)) *MeasurementCommonInterface_GetDataForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementIdType)) + }) + return _c +} + +func (_c *MeasurementCommonInterface_GetDataForId_Call) Return(_a0 *model.MeasurementDataType, _a1 error) *MeasurementCommonInterface_GetDataForId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementCommonInterface_GetDataForId_Call) RunAndReturn(run func(model.MeasurementIdType) (*model.MeasurementDataType, error)) *MeasurementCommonInterface_GetDataForId_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionForId provides a mock function with given fields: measurementId +func (_m *MeasurementCommonInterface) GetDescriptionForId(measurementId model.MeasurementIdType) (*model.MeasurementDescriptionDataType, error) { + ret := _m.Called(measurementId) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionForId") + } + + var r0 *model.MeasurementDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.MeasurementIdType) (*model.MeasurementDescriptionDataType, error)); ok { + return rf(measurementId) + } + if rf, ok := ret.Get(0).(func(model.MeasurementIdType) *model.MeasurementDescriptionDataType); ok { + r0 = rf(measurementId) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MeasurementDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.MeasurementIdType) error); ok { + r1 = rf(measurementId) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementCommonInterface_GetDescriptionForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionForId' +type MeasurementCommonInterface_GetDescriptionForId_Call struct { + *mock.Call +} + +// GetDescriptionForId is a helper method to define mock.On call +// - measurementId model.MeasurementIdType +func (_e *MeasurementCommonInterface_Expecter) GetDescriptionForId(measurementId interface{}) *MeasurementCommonInterface_GetDescriptionForId_Call { + return &MeasurementCommonInterface_GetDescriptionForId_Call{Call: _e.mock.On("GetDescriptionForId", measurementId)} +} + +func (_c *MeasurementCommonInterface_GetDescriptionForId_Call) Run(run func(measurementId model.MeasurementIdType)) *MeasurementCommonInterface_GetDescriptionForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementIdType)) + }) + return _c +} + +func (_c *MeasurementCommonInterface_GetDescriptionForId_Call) Return(_a0 *model.MeasurementDescriptionDataType, _a1 error) *MeasurementCommonInterface_GetDescriptionForId_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementCommonInterface_GetDescriptionForId_Call) RunAndReturn(run func(model.MeasurementIdType) (*model.MeasurementDescriptionDataType, error)) *MeasurementCommonInterface_GetDescriptionForId_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionsForFilter provides a mock function with given fields: filter +func (_m *MeasurementCommonInterface) GetDescriptionsForFilter(filter model.MeasurementDescriptionDataType) ([]model.MeasurementDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionsForFilter") + } + + var r0 []model.MeasurementDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.MeasurementDescriptionDataType) ([]model.MeasurementDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.MeasurementDescriptionDataType) []model.MeasurementDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.MeasurementDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.MeasurementDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// MeasurementCommonInterface_GetDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionsForFilter' +type MeasurementCommonInterface_GetDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetDescriptionsForFilter is a helper method to define mock.On call +// - filter model.MeasurementDescriptionDataType +func (_e *MeasurementCommonInterface_Expecter) GetDescriptionsForFilter(filter interface{}) *MeasurementCommonInterface_GetDescriptionsForFilter_Call { + return &MeasurementCommonInterface_GetDescriptionsForFilter_Call{Call: _e.mock.On("GetDescriptionsForFilter", filter)} +} + +func (_c *MeasurementCommonInterface_GetDescriptionsForFilter_Call) Run(run func(filter model.MeasurementDescriptionDataType)) *MeasurementCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementDescriptionDataType)) + }) + return _c +} + +func (_c *MeasurementCommonInterface_GetDescriptionsForFilter_Call) Return(_a0 []model.MeasurementDescriptionDataType, _a1 error) *MeasurementCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *MeasurementCommonInterface_GetDescriptionsForFilter_Call) RunAndReturn(run func(model.MeasurementDescriptionDataType) ([]model.MeasurementDescriptionDataType, error)) *MeasurementCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewMeasurementCommonInterface creates a new instance of MeasurementCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMeasurementCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *MeasurementCommonInterface { + mock := &MeasurementCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/MeasurementServerInterface.go b/mocks/MeasurementServerInterface.go new file mode 100644 index 00000000..0f884d36 --- /dev/null +++ b/mocks/MeasurementServerInterface.go @@ -0,0 +1,179 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// MeasurementServerInterface is an autogenerated mock type for the MeasurementServerInterface type +type MeasurementServerInterface struct { + mock.Mock +} + +type MeasurementServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *MeasurementServerInterface) EXPECT() *MeasurementServerInterface_Expecter { + return &MeasurementServerInterface_Expecter{mock: &_m.Mock} +} + +// AddDescription provides a mock function with given fields: description +func (_m *MeasurementServerInterface) AddDescription(description model.MeasurementDescriptionDataType) *model.MeasurementIdType { + ret := _m.Called(description) + + if len(ret) == 0 { + panic("no return value specified for AddDescription") + } + + var r0 *model.MeasurementIdType + if rf, ok := ret.Get(0).(func(model.MeasurementDescriptionDataType) *model.MeasurementIdType); ok { + r0 = rf(description) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MeasurementIdType) + } + } + + return r0 +} + +// MeasurementServerInterface_AddDescription_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddDescription' +type MeasurementServerInterface_AddDescription_Call struct { + *mock.Call +} + +// AddDescription is a helper method to define mock.On call +// - description model.MeasurementDescriptionDataType +func (_e *MeasurementServerInterface_Expecter) AddDescription(description interface{}) *MeasurementServerInterface_AddDescription_Call { + return &MeasurementServerInterface_AddDescription_Call{Call: _e.mock.On("AddDescription", description)} +} + +func (_c *MeasurementServerInterface_AddDescription_Call) Run(run func(description model.MeasurementDescriptionDataType)) *MeasurementServerInterface_AddDescription_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementDescriptionDataType)) + }) + return _c +} + +func (_c *MeasurementServerInterface_AddDescription_Call) Return(_a0 *model.MeasurementIdType) *MeasurementServerInterface_AddDescription_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MeasurementServerInterface_AddDescription_Call) RunAndReturn(run func(model.MeasurementDescriptionDataType) *model.MeasurementIdType) *MeasurementServerInterface_AddDescription_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDataForFilter provides a mock function with given fields: data, deleteElements, filter +func (_m *MeasurementServerInterface) UpdateDataForFilter(data model.MeasurementDataType, deleteElements *model.MeasurementDataElementsType, filter model.MeasurementDescriptionDataType) error { + ret := _m.Called(data, deleteElements, filter) + + if len(ret) == 0 { + panic("no return value specified for UpdateDataForFilter") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.MeasurementDataType, *model.MeasurementDataElementsType, model.MeasurementDescriptionDataType) error); ok { + r0 = rf(data, deleteElements, filter) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MeasurementServerInterface_UpdateDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDataForFilter' +type MeasurementServerInterface_UpdateDataForFilter_Call struct { + *mock.Call +} + +// UpdateDataForFilter is a helper method to define mock.On call +// - data model.MeasurementDataType +// - deleteElements *model.MeasurementDataElementsType +// - filter model.MeasurementDescriptionDataType +func (_e *MeasurementServerInterface_Expecter) UpdateDataForFilter(data interface{}, deleteElements interface{}, filter interface{}) *MeasurementServerInterface_UpdateDataForFilter_Call { + return &MeasurementServerInterface_UpdateDataForFilter_Call{Call: _e.mock.On("UpdateDataForFilter", data, deleteElements, filter)} +} + +func (_c *MeasurementServerInterface_UpdateDataForFilter_Call) Run(run func(data model.MeasurementDataType, deleteElements *model.MeasurementDataElementsType, filter model.MeasurementDescriptionDataType)) *MeasurementServerInterface_UpdateDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementDataType), args[1].(*model.MeasurementDataElementsType), args[2].(model.MeasurementDescriptionDataType)) + }) + return _c +} + +func (_c *MeasurementServerInterface_UpdateDataForFilter_Call) Return(_a0 error) *MeasurementServerInterface_UpdateDataForFilter_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MeasurementServerInterface_UpdateDataForFilter_Call) RunAndReturn(run func(model.MeasurementDataType, *model.MeasurementDataElementsType, model.MeasurementDescriptionDataType) error) *MeasurementServerInterface_UpdateDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// UpdateDataForId provides a mock function with given fields: data, deleteElements, measurementId +func (_m *MeasurementServerInterface) UpdateDataForId(data model.MeasurementDataType, deleteElements *model.MeasurementDataElementsType, measurementId model.MeasurementIdType) error { + ret := _m.Called(data, deleteElements, measurementId) + + if len(ret) == 0 { + panic("no return value specified for UpdateDataForId") + } + + var r0 error + if rf, ok := ret.Get(0).(func(model.MeasurementDataType, *model.MeasurementDataElementsType, model.MeasurementIdType) error); ok { + r0 = rf(data, deleteElements, measurementId) + } else { + r0 = ret.Error(0) + } + + return r0 +} + +// MeasurementServerInterface_UpdateDataForId_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'UpdateDataForId' +type MeasurementServerInterface_UpdateDataForId_Call struct { + *mock.Call +} + +// UpdateDataForId is a helper method to define mock.On call +// - data model.MeasurementDataType +// - deleteElements *model.MeasurementDataElementsType +// - measurementId model.MeasurementIdType +func (_e *MeasurementServerInterface_Expecter) UpdateDataForId(data interface{}, deleteElements interface{}, measurementId interface{}) *MeasurementServerInterface_UpdateDataForId_Call { + return &MeasurementServerInterface_UpdateDataForId_Call{Call: _e.mock.On("UpdateDataForId", data, deleteElements, measurementId)} +} + +func (_c *MeasurementServerInterface_UpdateDataForId_Call) Run(run func(data model.MeasurementDataType, deleteElements *model.MeasurementDataElementsType, measurementId model.MeasurementIdType)) *MeasurementServerInterface_UpdateDataForId_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.MeasurementDataType), args[1].(*model.MeasurementDataElementsType), args[2].(model.MeasurementIdType)) + }) + return _c +} + +func (_c *MeasurementServerInterface_UpdateDataForId_Call) Return(_a0 error) *MeasurementServerInterface_UpdateDataForId_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *MeasurementServerInterface_UpdateDataForId_Call) RunAndReturn(run func(model.MeasurementDataType, *model.MeasurementDataElementsType, model.MeasurementIdType) error) *MeasurementServerInterface_UpdateDataForId_Call { + _c.Call.Return(run) + return _c +} + +// NewMeasurementServerInterface creates a new instance of MeasurementServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewMeasurementServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *MeasurementServerInterface { + mock := &MeasurementServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/ServiceInterface.go b/mocks/ServiceInterface.go index 7b71bf71..ad2bc80f 100644 --- a/mocks/ServiceInterface.go +++ b/mocks/ServiceInterface.go @@ -140,6 +140,51 @@ func (_c *ServiceInterface_DisconnectSKI_Call) RunAndReturn(run func(string, str return _c } +// IsAutoAcceptEnabled provides a mock function with given fields: +func (_m *ServiceInterface) IsAutoAcceptEnabled() bool { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for IsAutoAcceptEnabled") + } + + var r0 bool + if rf, ok := ret.Get(0).(func() bool); ok { + r0 = rf() + } else { + r0 = ret.Get(0).(bool) + } + + return r0 +} + +// ServiceInterface_IsAutoAcceptEnabled_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsAutoAcceptEnabled' +type ServiceInterface_IsAutoAcceptEnabled_Call struct { + *mock.Call +} + +// IsAutoAcceptEnabled is a helper method to define mock.On call +func (_e *ServiceInterface_Expecter) IsAutoAcceptEnabled() *ServiceInterface_IsAutoAcceptEnabled_Call { + return &ServiceInterface_IsAutoAcceptEnabled_Call{Call: _e.mock.On("IsAutoAcceptEnabled")} +} + +func (_c *ServiceInterface_IsAutoAcceptEnabled_Call) Run(run func()) *ServiceInterface_IsAutoAcceptEnabled_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *ServiceInterface_IsAutoAcceptEnabled_Call) Return(_a0 bool) *ServiceInterface_IsAutoAcceptEnabled_Call { + _c.Call.Return(_a0) + return _c +} + +func (_c *ServiceInterface_IsAutoAcceptEnabled_Call) RunAndReturn(run func() bool) *ServiceInterface_IsAutoAcceptEnabled_Call { + _c.Call.Return(run) + return _c +} + // LocalDevice provides a mock function with given fields: func (_m *ServiceInterface) LocalDevice() spine_goapi.DeviceLocalInterface { ret := _m.Called() diff --git a/mocks/SmartEnergyManagementPsClientInterface.go b/mocks/SmartEnergyManagementPsClientInterface.go new file mode 100644 index 00000000..da5da3fd --- /dev/null +++ b/mocks/SmartEnergyManagementPsClientInterface.go @@ -0,0 +1,150 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// SmartEnergyManagementPsClientInterface is an autogenerated mock type for the SmartEnergyManagementPsClientInterface type +type SmartEnergyManagementPsClientInterface struct { + mock.Mock +} + +type SmartEnergyManagementPsClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *SmartEnergyManagementPsClientInterface) EXPECT() *SmartEnergyManagementPsClientInterface_Expecter { + return &SmartEnergyManagementPsClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestData provides a mock function with given fields: +func (_m *SmartEnergyManagementPsClientInterface) RequestData() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SmartEnergyManagementPsClientInterface_RequestData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestData' +type SmartEnergyManagementPsClientInterface_RequestData_Call struct { + *mock.Call +} + +// RequestData is a helper method to define mock.On call +func (_e *SmartEnergyManagementPsClientInterface_Expecter) RequestData() *SmartEnergyManagementPsClientInterface_RequestData_Call { + return &SmartEnergyManagementPsClientInterface_RequestData_Call{Call: _e.mock.On("RequestData")} +} + +func (_c *SmartEnergyManagementPsClientInterface_RequestData_Call) Run(run func()) *SmartEnergyManagementPsClientInterface_RequestData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SmartEnergyManagementPsClientInterface_RequestData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *SmartEnergyManagementPsClientInterface_RequestData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SmartEnergyManagementPsClientInterface_RequestData_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *SmartEnergyManagementPsClientInterface_RequestData_Call { + _c.Call.Return(run) + return _c +} + +// WriteData provides a mock function with given fields: data +func (_m *SmartEnergyManagementPsClientInterface) WriteData(data *model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func(*model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func(*model.SmartEnergyManagementPsDataType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func(*model.SmartEnergyManagementPsDataType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SmartEnergyManagementPsClientInterface_WriteData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteData' +type SmartEnergyManagementPsClientInterface_WriteData_Call struct { + *mock.Call +} + +// WriteData is a helper method to define mock.On call +// - data *model.SmartEnergyManagementPsDataType +func (_e *SmartEnergyManagementPsClientInterface_Expecter) WriteData(data interface{}) *SmartEnergyManagementPsClientInterface_WriteData_Call { + return &SmartEnergyManagementPsClientInterface_WriteData_Call{Call: _e.mock.On("WriteData", data)} +} + +func (_c *SmartEnergyManagementPsClientInterface_WriteData_Call) Run(run func(data *model.SmartEnergyManagementPsDataType)) *SmartEnergyManagementPsClientInterface_WriteData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(*model.SmartEnergyManagementPsDataType)) + }) + return _c +} + +func (_c *SmartEnergyManagementPsClientInterface_WriteData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *SmartEnergyManagementPsClientInterface_WriteData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SmartEnergyManagementPsClientInterface_WriteData_Call) RunAndReturn(run func(*model.SmartEnergyManagementPsDataType) (*model.MsgCounterType, error)) *SmartEnergyManagementPsClientInterface_WriteData_Call { + _c.Call.Return(run) + return _c +} + +// NewSmartEnergyManagementPsClientInterface creates a new instance of SmartEnergyManagementPsClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSmartEnergyManagementPsClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *SmartEnergyManagementPsClientInterface { + mock := &SmartEnergyManagementPsClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/SmartEnergyManagementPsCommonInterface.go b/mocks/SmartEnergyManagementPsCommonInterface.go new file mode 100644 index 00000000..a13b8387 --- /dev/null +++ b/mocks/SmartEnergyManagementPsCommonInterface.go @@ -0,0 +1,92 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// SmartEnergyManagementPsCommonInterface is an autogenerated mock type for the SmartEnergyManagementPsCommonInterface type +type SmartEnergyManagementPsCommonInterface struct { + mock.Mock +} + +type SmartEnergyManagementPsCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *SmartEnergyManagementPsCommonInterface) EXPECT() *SmartEnergyManagementPsCommonInterface_Expecter { + return &SmartEnergyManagementPsCommonInterface_Expecter{mock: &_m.Mock} +} + +// GetData provides a mock function with given fields: +func (_m *SmartEnergyManagementPsCommonInterface) GetData() (*model.SmartEnergyManagementPsDataType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetData") + } + + var r0 *model.SmartEnergyManagementPsDataType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.SmartEnergyManagementPsDataType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.SmartEnergyManagementPsDataType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.SmartEnergyManagementPsDataType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// SmartEnergyManagementPsCommonInterface_GetData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetData' +type SmartEnergyManagementPsCommonInterface_GetData_Call struct { + *mock.Call +} + +// GetData is a helper method to define mock.On call +func (_e *SmartEnergyManagementPsCommonInterface_Expecter) GetData() *SmartEnergyManagementPsCommonInterface_GetData_Call { + return &SmartEnergyManagementPsCommonInterface_GetData_Call{Call: _e.mock.On("GetData")} +} + +func (_c *SmartEnergyManagementPsCommonInterface_GetData_Call) Run(run func()) *SmartEnergyManagementPsCommonInterface_GetData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *SmartEnergyManagementPsCommonInterface_GetData_Call) Return(_a0 *model.SmartEnergyManagementPsDataType, _a1 error) *SmartEnergyManagementPsCommonInterface_GetData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *SmartEnergyManagementPsCommonInterface_GetData_Call) RunAndReturn(run func() (*model.SmartEnergyManagementPsDataType, error)) *SmartEnergyManagementPsCommonInterface_GetData_Call { + _c.Call.Return(run) + return _c +} + +// NewSmartEnergyManagementPsCommonInterface creates a new instance of SmartEnergyManagementPsCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSmartEnergyManagementPsCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *SmartEnergyManagementPsCommonInterface { + mock := &SmartEnergyManagementPsCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/SmartEnergyManagementPsServerInterface.go b/mocks/SmartEnergyManagementPsServerInterface.go new file mode 100644 index 00000000..58093350 --- /dev/null +++ b/mocks/SmartEnergyManagementPsServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// SmartEnergyManagementPsServerInterface is an autogenerated mock type for the SmartEnergyManagementPsServerInterface type +type SmartEnergyManagementPsServerInterface struct { + mock.Mock +} + +type SmartEnergyManagementPsServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *SmartEnergyManagementPsServerInterface) EXPECT() *SmartEnergyManagementPsServerInterface_Expecter { + return &SmartEnergyManagementPsServerInterface_Expecter{mock: &_m.Mock} +} + +// NewSmartEnergyManagementPsServerInterface creates a new instance of SmartEnergyManagementPsServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewSmartEnergyManagementPsServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *SmartEnergyManagementPsServerInterface { + mock := &SmartEnergyManagementPsServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/TimeSeriesClientInterface.go b/mocks/TimeSeriesClientInterface.go new file mode 100644 index 00000000..34e82b0f --- /dev/null +++ b/mocks/TimeSeriesClientInterface.go @@ -0,0 +1,264 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// TimeSeriesClientInterface is an autogenerated mock type for the TimeSeriesClientInterface type +type TimeSeriesClientInterface struct { + mock.Mock +} + +type TimeSeriesClientInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *TimeSeriesClientInterface) EXPECT() *TimeSeriesClientInterface_Expecter { + return &TimeSeriesClientInterface_Expecter{mock: &_m.Mock} +} + +// RequestConstraints provides a mock function with given fields: +func (_m *TimeSeriesClientInterface) RequestConstraints() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestConstraints") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesClientInterface_RequestConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestConstraints' +type TimeSeriesClientInterface_RequestConstraints_Call struct { + *mock.Call +} + +// RequestConstraints is a helper method to define mock.On call +func (_e *TimeSeriesClientInterface_Expecter) RequestConstraints() *TimeSeriesClientInterface_RequestConstraints_Call { + return &TimeSeriesClientInterface_RequestConstraints_Call{Call: _e.mock.On("RequestConstraints")} +} + +func (_c *TimeSeriesClientInterface_RequestConstraints_Call) Run(run func()) *TimeSeriesClientInterface_RequestConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestConstraints_Call) Return(_a0 *model.MsgCounterType, _a1 error) *TimeSeriesClientInterface_RequestConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestConstraints_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *TimeSeriesClientInterface_RequestConstraints_Call { + _c.Call.Return(run) + return _c +} + +// RequestData provides a mock function with given fields: +func (_m *TimeSeriesClientInterface) RequestData() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesClientInterface_RequestData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestData' +type TimeSeriesClientInterface_RequestData_Call struct { + *mock.Call +} + +// RequestData is a helper method to define mock.On call +func (_e *TimeSeriesClientInterface_Expecter) RequestData() *TimeSeriesClientInterface_RequestData_Call { + return &TimeSeriesClientInterface_RequestData_Call{Call: _e.mock.On("RequestData")} +} + +func (_c *TimeSeriesClientInterface_RequestData_Call) Run(run func()) *TimeSeriesClientInterface_RequestData_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *TimeSeriesClientInterface_RequestData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestData_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *TimeSeriesClientInterface_RequestData_Call { + _c.Call.Return(run) + return _c +} + +// RequestDescriptions provides a mock function with given fields: +func (_m *TimeSeriesClientInterface) RequestDescriptions() (*model.MsgCounterType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for RequestDescriptions") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func() (*model.MsgCounterType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() *model.MsgCounterType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesClientInterface_RequestDescriptions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RequestDescriptions' +type TimeSeriesClientInterface_RequestDescriptions_Call struct { + *mock.Call +} + +// RequestDescriptions is a helper method to define mock.On call +func (_e *TimeSeriesClientInterface_Expecter) RequestDescriptions() *TimeSeriesClientInterface_RequestDescriptions_Call { + return &TimeSeriesClientInterface_RequestDescriptions_Call{Call: _e.mock.On("RequestDescriptions")} +} + +func (_c *TimeSeriesClientInterface_RequestDescriptions_Call) Run(run func()) *TimeSeriesClientInterface_RequestDescriptions_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestDescriptions_Call) Return(_a0 *model.MsgCounterType, _a1 error) *TimeSeriesClientInterface_RequestDescriptions_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesClientInterface_RequestDescriptions_Call) RunAndReturn(run func() (*model.MsgCounterType, error)) *TimeSeriesClientInterface_RequestDescriptions_Call { + _c.Call.Return(run) + return _c +} + +// WriteData provides a mock function with given fields: data +func (_m *TimeSeriesClientInterface) WriteData(data []model.TimeSeriesDataType) (*model.MsgCounterType, error) { + ret := _m.Called(data) + + if len(ret) == 0 { + panic("no return value specified for WriteData") + } + + var r0 *model.MsgCounterType + var r1 error + if rf, ok := ret.Get(0).(func([]model.TimeSeriesDataType) (*model.MsgCounterType, error)); ok { + return rf(data) + } + if rf, ok := ret.Get(0).(func([]model.TimeSeriesDataType) *model.MsgCounterType); ok { + r0 = rf(data) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(*model.MsgCounterType) + } + } + + if rf, ok := ret.Get(1).(func([]model.TimeSeriesDataType) error); ok { + r1 = rf(data) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesClientInterface_WriteData_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'WriteData' +type TimeSeriesClientInterface_WriteData_Call struct { + *mock.Call +} + +// WriteData is a helper method to define mock.On call +// - data []model.TimeSeriesDataType +func (_e *TimeSeriesClientInterface_Expecter) WriteData(data interface{}) *TimeSeriesClientInterface_WriteData_Call { + return &TimeSeriesClientInterface_WriteData_Call{Call: _e.mock.On("WriteData", data)} +} + +func (_c *TimeSeriesClientInterface_WriteData_Call) Run(run func(data []model.TimeSeriesDataType)) *TimeSeriesClientInterface_WriteData_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].([]model.TimeSeriesDataType)) + }) + return _c +} + +func (_c *TimeSeriesClientInterface_WriteData_Call) Return(_a0 *model.MsgCounterType, _a1 error) *TimeSeriesClientInterface_WriteData_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesClientInterface_WriteData_Call) RunAndReturn(run func([]model.TimeSeriesDataType) (*model.MsgCounterType, error)) *TimeSeriesClientInterface_WriteData_Call { + _c.Call.Return(run) + return _c +} + +// NewTimeSeriesClientInterface creates a new instance of TimeSeriesClientInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTimeSeriesClientInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *TimeSeriesClientInterface { + mock := &TimeSeriesClientInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/TimeSeriesCommonInterface.go b/mocks/TimeSeriesCommonInterface.go new file mode 100644 index 00000000..e5f95c8c --- /dev/null +++ b/mocks/TimeSeriesCommonInterface.go @@ -0,0 +1,208 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import ( + model "github.com/enbility/spine-go/model" + mock "github.com/stretchr/testify/mock" +) + +// TimeSeriesCommonInterface is an autogenerated mock type for the TimeSeriesCommonInterface type +type TimeSeriesCommonInterface struct { + mock.Mock +} + +type TimeSeriesCommonInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *TimeSeriesCommonInterface) EXPECT() *TimeSeriesCommonInterface_Expecter { + return &TimeSeriesCommonInterface_Expecter{mock: &_m.Mock} +} + +// GetConstraints provides a mock function with given fields: +func (_m *TimeSeriesCommonInterface) GetConstraints() ([]model.TimeSeriesConstraintsDataType, error) { + ret := _m.Called() + + if len(ret) == 0 { + panic("no return value specified for GetConstraints") + } + + var r0 []model.TimeSeriesConstraintsDataType + var r1 error + if rf, ok := ret.Get(0).(func() ([]model.TimeSeriesConstraintsDataType, error)); ok { + return rf() + } + if rf, ok := ret.Get(0).(func() []model.TimeSeriesConstraintsDataType); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.TimeSeriesConstraintsDataType) + } + } + + if rf, ok := ret.Get(1).(func() error); ok { + r1 = rf() + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesCommonInterface_GetConstraints_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetConstraints' +type TimeSeriesCommonInterface_GetConstraints_Call struct { + *mock.Call +} + +// GetConstraints is a helper method to define mock.On call +func (_e *TimeSeriesCommonInterface_Expecter) GetConstraints() *TimeSeriesCommonInterface_GetConstraints_Call { + return &TimeSeriesCommonInterface_GetConstraints_Call{Call: _e.mock.On("GetConstraints")} +} + +func (_c *TimeSeriesCommonInterface_GetConstraints_Call) Run(run func()) *TimeSeriesCommonInterface_GetConstraints_Call { + _c.Call.Run(func(args mock.Arguments) { + run() + }) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetConstraints_Call) Return(_a0 []model.TimeSeriesConstraintsDataType, _a1 error) *TimeSeriesCommonInterface_GetConstraints_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetConstraints_Call) RunAndReturn(run func() ([]model.TimeSeriesConstraintsDataType, error)) *TimeSeriesCommonInterface_GetConstraints_Call { + _c.Call.Return(run) + return _c +} + +// GetDataForFilter provides a mock function with given fields: filter +func (_m *TimeSeriesCommonInterface) GetDataForFilter(filter model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDataForFilter") + } + + var r0 []model.TimeSeriesDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.TimeSeriesDescriptionDataType) []model.TimeSeriesDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.TimeSeriesDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.TimeSeriesDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesCommonInterface_GetDataForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDataForFilter' +type TimeSeriesCommonInterface_GetDataForFilter_Call struct { + *mock.Call +} + +// GetDataForFilter is a helper method to define mock.On call +// - filter model.TimeSeriesDescriptionDataType +func (_e *TimeSeriesCommonInterface_Expecter) GetDataForFilter(filter interface{}) *TimeSeriesCommonInterface_GetDataForFilter_Call { + return &TimeSeriesCommonInterface_GetDataForFilter_Call{Call: _e.mock.On("GetDataForFilter", filter)} +} + +func (_c *TimeSeriesCommonInterface_GetDataForFilter_Call) Run(run func(filter model.TimeSeriesDescriptionDataType)) *TimeSeriesCommonInterface_GetDataForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.TimeSeriesDescriptionDataType)) + }) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetDataForFilter_Call) Return(_a0 []model.TimeSeriesDataType, _a1 error) *TimeSeriesCommonInterface_GetDataForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetDataForFilter_Call) RunAndReturn(run func(model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDataType, error)) *TimeSeriesCommonInterface_GetDataForFilter_Call { + _c.Call.Return(run) + return _c +} + +// GetDescriptionsForFilter provides a mock function with given fields: filter +func (_m *TimeSeriesCommonInterface) GetDescriptionsForFilter(filter model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDescriptionDataType, error) { + ret := _m.Called(filter) + + if len(ret) == 0 { + panic("no return value specified for GetDescriptionsForFilter") + } + + var r0 []model.TimeSeriesDescriptionDataType + var r1 error + if rf, ok := ret.Get(0).(func(model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDescriptionDataType, error)); ok { + return rf(filter) + } + if rf, ok := ret.Get(0).(func(model.TimeSeriesDescriptionDataType) []model.TimeSeriesDescriptionDataType); ok { + r0 = rf(filter) + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).([]model.TimeSeriesDescriptionDataType) + } + } + + if rf, ok := ret.Get(1).(func(model.TimeSeriesDescriptionDataType) error); ok { + r1 = rf(filter) + } else { + r1 = ret.Error(1) + } + + return r0, r1 +} + +// TimeSeriesCommonInterface_GetDescriptionsForFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetDescriptionsForFilter' +type TimeSeriesCommonInterface_GetDescriptionsForFilter_Call struct { + *mock.Call +} + +// GetDescriptionsForFilter is a helper method to define mock.On call +// - filter model.TimeSeriesDescriptionDataType +func (_e *TimeSeriesCommonInterface_Expecter) GetDescriptionsForFilter(filter interface{}) *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call { + return &TimeSeriesCommonInterface_GetDescriptionsForFilter_Call{Call: _e.mock.On("GetDescriptionsForFilter", filter)} +} + +func (_c *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call) Run(run func(filter model.TimeSeriesDescriptionDataType)) *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Run(func(args mock.Arguments) { + run(args[0].(model.TimeSeriesDescriptionDataType)) + }) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call) Return(_a0 []model.TimeSeriesDescriptionDataType, _a1 error) *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(_a0, _a1) + return _c +} + +func (_c *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call) RunAndReturn(run func(model.TimeSeriesDescriptionDataType) ([]model.TimeSeriesDescriptionDataType, error)) *TimeSeriesCommonInterface_GetDescriptionsForFilter_Call { + _c.Call.Return(run) + return _c +} + +// NewTimeSeriesCommonInterface creates a new instance of TimeSeriesCommonInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTimeSeriesCommonInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *TimeSeriesCommonInterface { + mock := &TimeSeriesCommonInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} diff --git a/mocks/TimeSeriesServerInterface.go b/mocks/TimeSeriesServerInterface.go new file mode 100644 index 00000000..b87c0f4e --- /dev/null +++ b/mocks/TimeSeriesServerInterface.go @@ -0,0 +1,32 @@ +// Code generated by mockery v2.42.1. DO NOT EDIT. + +package mocks + +import mock "github.com/stretchr/testify/mock" + +// TimeSeriesServerInterface is an autogenerated mock type for the TimeSeriesServerInterface type +type TimeSeriesServerInterface struct { + mock.Mock +} + +type TimeSeriesServerInterface_Expecter struct { + mock *mock.Mock +} + +func (_m *TimeSeriesServerInterface) EXPECT() *TimeSeriesServerInterface_Expecter { + return &TimeSeriesServerInterface_Expecter{mock: &_m.Mock} +} + +// NewTimeSeriesServerInterface creates a new instance of TimeSeriesServerInterface. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +// The first argument is typically a *testing.T value. +func NewTimeSeriesServerInterface(t interface { + mock.TestingT + Cleanup(func()) +}) *TimeSeriesServerInterface { + mock := &TimeSeriesServerInterface{} + mock.Mock.Test(t) + + t.Cleanup(func() { mock.AssertExpectations(t) }) + + return mock +} From 69840579204620f67f20fc3c89f4972a29fa5a37 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 28 May 2024 19:45:28 +0200 Subject: [PATCH 2/3] Fix codefactor warnings --- features/server/deviceconfiguration.go | 6 +++--- features/server/deviceconfiguration_test.go | 4 ++-- features/server/electricalconnection.go | 6 +++--- features/server/electricalconnection_test.go | 4 ++-- features/server/loadcontrol.go | 6 +++--- features/server/loadcontrol_test.go | 4 ++-- features/server/measurement.go | 6 +++--- features/server/measurement_test.go | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/features/server/deviceconfiguration.go b/features/server/deviceconfiguration.go index e30c7b8a..5020f257 100644 --- a/features/server/deviceconfiguration.go +++ b/features/server/deviceconfiguration.go @@ -108,9 +108,9 @@ func (d *DeviceConfiguration) UpdateKeyValueDataForFilter( } partial := model.NewFilterTypePartial() - var delete *model.FilterType + var deleteFilter *model.FilterType if deleteElements != nil { - delete = &model.FilterType{ + deleteFilter = &model.FilterType{ DeviceConfigurationKeyValueListDataSelectors: &model.DeviceConfigurationKeyValueListDataSelectorsType{ KeyId: description.KeyId, }, @@ -118,7 +118,7 @@ func (d *DeviceConfiguration) UpdateKeyValueDataForFilter( } } - if err := d.featureLocal.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, datalist, partial, delete); err != nil { + if err := d.featureLocal.UpdateData(model.FunctionTypeDeviceConfigurationKeyValueListData, datalist, partial, deleteFilter); err != nil { return errors.New(err.String()) } diff --git a/features/server/deviceconfiguration_test.go b/features/server/deviceconfiguration_test.go index f6b874e2..56ff39c2 100644 --- a/features/server/deviceconfiguration_test.go +++ b/features/server/deviceconfiguration_test.go @@ -230,11 +230,11 @@ func (s *DeviceConfigurationSuite) Test_UpdateKeyValueDataForFilter() { err = s.sut.UpdateKeyValueDataForFilter(data, nil, filter) assert.Nil(s.T(), err) - delete := &model.DeviceConfigurationKeyValueDataElementsType{ + deleteElements := &model.DeviceConfigurationKeyValueDataElementsType{ Value: &model.DeviceConfigurationKeyValueValueElementsType{}, } data = model.DeviceConfigurationKeyValueDataType{} - err = s.sut.UpdateKeyValueDataForFilter(data, delete, filter) + err = s.sut.UpdateKeyValueDataForFilter(data, deleteElements, filter) assert.Nil(s.T(), err) result, err = s.sut.GetKeyValueDataForFilter(filter) diff --git a/features/server/electricalconnection.go b/features/server/electricalconnection.go index 0d91f708..688c74eb 100644 --- a/features/server/electricalconnection.go +++ b/features/server/electricalconnection.go @@ -163,9 +163,9 @@ func (e *ElectricalConnection) UpdateCharacteristic( } partial := model.NewFilterTypePartial() - var delete *model.FilterType + var deleteFilter *model.FilterType if deleteElements != nil { - delete = &model.FilterType{ + deleteFilter = &model.FilterType{ ElectricalConnectionCharacteristicListDataSelectors: &model.ElectricalConnectionCharacteristicListDataSelectorsType{ CharacteristicId: data.CharacteristicId, }, @@ -177,7 +177,7 @@ func (e *ElectricalConnection) UpdateCharacteristic( ElectricalConnectionCharacteristicData: []model.ElectricalConnectionCharacteristicDataType{data}, } - if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, datalist, partial, delete); err != nil { + if err := e.featureLocal.UpdateData(model.FunctionTypeElectricalConnectionCharacteristicListData, datalist, partial, deleteFilter); err != nil { return errors.New(err.String()) } diff --git a/features/server/electricalconnection_test.go b/features/server/electricalconnection_test.go index b690714f..0d84afac 100644 --- a/features/server/electricalconnection_test.go +++ b/features/server/electricalconnection_test.go @@ -238,11 +238,11 @@ func (s *ElectricalConnectionSuite) Test_UpdateCharacteristic() { err = s.sut.UpdateCharacteristic(charData, nil) assert.Nil(s.T(), err) - delete := &model.ElectricalConnectionCharacteristicDataElementsType{ + deleteElements := &model.ElectricalConnectionCharacteristicDataElementsType{ Value: &model.ScaledNumberElementsType{}, } charData.Value = nil - err = s.sut.UpdateCharacteristic(charData, delete) + err = s.sut.UpdateCharacteristic(charData, deleteElements) assert.Nil(s.T(), err) data, err = s.sut.GetCharacteristicsForFilter(filter) diff --git a/features/server/loadcontrol.go b/features/server/loadcontrol.go index 39e80591..b3524e3f 100644 --- a/features/server/loadcontrol.go +++ b/features/server/loadcontrol.go @@ -106,9 +106,9 @@ func (l *LoadControl) UpdateLimitDataForFilter( } partial := model.NewFilterTypePartial() - var delete *model.FilterType + var deleteFilter *model.FilterType if deleteElements != nil { - delete = &model.FilterType{ + deleteFilter = &model.FilterType{ LoadControlLimitListDataSelectors: &model.LoadControlLimitListDataSelectorsType{ LimitId: description.LimitId, }, @@ -116,7 +116,7 @@ func (l *LoadControl) UpdateLimitDataForFilter( } } - if err := l.featureLocal.UpdateData(model.FunctionTypeLoadControlLimitListData, datalist, partial, delete); err != nil { + if err := l.featureLocal.UpdateData(model.FunctionTypeLoadControlLimitListData, datalist, partial, deleteFilter); err != nil { return errors.New(err.String()) } diff --git a/features/server/loadcontrol_test.go b/features/server/loadcontrol_test.go index ea8fe26e..ec3bea3a 100644 --- a/features/server/loadcontrol_test.go +++ b/features/server/loadcontrol_test.go @@ -267,10 +267,10 @@ func (s *LoadControlSuite) Test_GetLimitData() { assert.Nil(s.T(), result) data = model.LoadControlLimitDataType{} - delete := &model.LoadControlLimitDataElementsType{ + deleteElements := &model.LoadControlLimitDataElementsType{ TimePeriod: &model.TimePeriodElementsType{}, } - err = s.sut.UpdateLimitDataForId(data, delete, *limitId) + err = s.sut.UpdateLimitDataForId(data, deleteElements, *limitId) assert.Nil(s.T(), err) result, err = s.sut.GetLimitDataForId(*limitId) diff --git a/features/server/measurement.go b/features/server/measurement.go index 992172db..3c73a1b5 100644 --- a/features/server/measurement.go +++ b/features/server/measurement.go @@ -108,9 +108,9 @@ func (m *Measurement) UpdateDataForFilter( } partial := model.NewFilterTypePartial() - var delete *model.FilterType + var deleteFilter *model.FilterType if deleteElements != nil { - delete = &model.FilterType{ + deleteFilter = &model.FilterType{ MeasurementListDataSelectors: &model.MeasurementListDataSelectorsType{ MeasurementId: description.MeasurementId, }, @@ -118,7 +118,7 @@ func (m *Measurement) UpdateDataForFilter( } } - if err := m.featureLocal.UpdateData(model.FunctionTypeMeasurementListData, datalist, partial, delete); err != nil { + if err := m.featureLocal.UpdateData(model.FunctionTypeMeasurementListData, datalist, partial, deleteFilter); err != nil { return errors.New(err.String()) } diff --git a/features/server/measurement_test.go b/features/server/measurement_test.go index 857d3a85..55f446bd 100644 --- a/features/server/measurement_test.go +++ b/features/server/measurement_test.go @@ -190,10 +190,10 @@ func (s *MeasurementSuite) Test_GetLimitData() { assert.Nil(s.T(), result) data = model.MeasurementDataType{} - delete := &model.MeasurementDataElementsType{ + deleteElements := &model.MeasurementDataElementsType{ Value: util.Ptr(model.ElementTagType{}), } - err = s.sut.UpdateDataForId(data, delete, *mId) + err = s.sut.UpdateDataForId(data, deleteElements, *mId) assert.Nil(s.T(), err) result, err = s.sut.GetDataForId(*mId) From 1db0856c68ff10aa34efbd5b43a8bb1f7353ef40 Mon Sep 17 00:00:00 2001 From: Andreas Linde Date: Tue, 28 May 2024 20:28:05 +0200 Subject: [PATCH 3/3] Update used packages and remove util - Remove util package, as it is only duplicate of one method of spineutils - Align package names --- features/client/deviceconfiguration.go | 2 +- features/client/deviceconfiguration_test.go | 2 +- features/client/helper_test.go | 2 +- features/client/incentivetable_test.go | 2 +- features/client/loadcontrol.go | 2 +- features/client/loadcontrol_test.go | 2 +- features/client/smartenergymanagementps.go | 2 +- features/client/timeseries_test.go | 2 +- features/internal/deviceclassification_test.go | 2 +- features/internal/deviceconfiguration_test.go | 2 +- features/internal/devicediagnosis_test.go | 2 +- features/internal/electricalconnection.go | 2 +- features/internal/electricalconnection_test.go | 2 +- features/internal/helper_test.go | 2 +- features/internal/identification_test.go | 2 +- features/internal/incentivetable_test.go | 2 +- features/internal/loadcontrol_test.go | 2 +- features/internal/measurement_test.go | 2 +- features/internal/timeseries_test.go | 2 +- features/server/deviceconfiguration.go | 2 +- features/server/deviceconfiguration_test.go | 16 ++++++++-------- features/server/devicediagnosis_test.go | 16 ++++++++-------- features/server/electricalconnection.go | 2 +- features/server/electricalconnection_test.go | 16 ++++++++-------- features/server/helper_test.go | 2 +- features/server/loadcontrol.go | 2 +- features/server/loadcontrol_test.go | 16 ++++++++-------- features/server/measurement.go | 2 +- features/server/measurement_test.go | 16 ++++++++-------- util/ptr.go | 5 ----- 30 files changed, 64 insertions(+), 69 deletions(-) delete mode 100644 util/ptr.go diff --git a/features/client/deviceconfiguration.go b/features/client/deviceconfiguration.go index ca6fb2db..bb9f754c 100644 --- a/features/client/deviceconfiguration.go +++ b/features/client/deviceconfiguration.go @@ -3,9 +3,9 @@ package client import ( "github.com/enbility/eebus-go/api" internal "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type DeviceConfiguration struct { diff --git a/features/client/deviceconfiguration_test.go b/features/client/deviceconfiguration_test.go index 5f74d8d3..9e728a88 100644 --- a/features/client/deviceconfiguration_test.go +++ b/features/client/deviceconfiguration_test.go @@ -4,11 +4,11 @@ import ( "testing" features "github.com/enbility/eebus-go/features/client" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/client/helper_test.go b/features/client/helper_test.go index 0e2ebc04..82285db8 100644 --- a/features/client/helper_test.go +++ b/features/client/helper_test.go @@ -5,11 +5,11 @@ import ( "sync" "time" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" ) diff --git a/features/client/incentivetable_test.go b/features/client/incentivetable_test.go index 763a9472..ca5dbb69 100644 --- a/features/client/incentivetable_test.go +++ b/features/client/incentivetable_test.go @@ -4,10 +4,10 @@ import ( "testing" features "github.com/enbility/eebus-go/features/client" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) diff --git a/features/client/loadcontrol.go b/features/client/loadcontrol.go index fac27c39..fa44577a 100644 --- a/features/client/loadcontrol.go +++ b/features/client/loadcontrol.go @@ -3,9 +3,9 @@ package client import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type LoadControl struct { diff --git a/features/client/loadcontrol_test.go b/features/client/loadcontrol_test.go index 99d67004..b9d37272 100644 --- a/features/client/loadcontrol_test.go +++ b/features/client/loadcontrol_test.go @@ -4,10 +4,10 @@ import ( "testing" features "github.com/enbility/eebus-go/features/client" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) diff --git a/features/client/smartenergymanagementps.go b/features/client/smartenergymanagementps.go index 0d5b542b..ed39d4fb 100644 --- a/features/client/smartenergymanagementps.go +++ b/features/client/smartenergymanagementps.go @@ -3,9 +3,9 @@ package client import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type SmartEnergyManagementPs struct { diff --git a/features/client/timeseries_test.go b/features/client/timeseries_test.go index 71762690..6cdeff90 100644 --- a/features/client/timeseries_test.go +++ b/features/client/timeseries_test.go @@ -4,10 +4,10 @@ import ( "testing" features "github.com/enbility/eebus-go/features/client" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) diff --git a/features/internal/deviceclassification_test.go b/features/internal/deviceclassification_test.go index ac7ee441..29395663 100644 --- a/features/internal/deviceclassification_test.go +++ b/features/internal/deviceclassification_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/suite" ) diff --git a/features/internal/deviceconfiguration_test.go b/features/internal/deviceconfiguration_test.go index 425737a3..cca780ae 100644 --- a/features/internal/deviceconfiguration_test.go +++ b/features/internal/deviceconfiguration_test.go @@ -5,10 +5,10 @@ import ( "time" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/devicediagnosis_test.go b/features/internal/devicediagnosis_test.go index bedc10ae..0db7f4f1 100644 --- a/features/internal/devicediagnosis_test.go +++ b/features/internal/devicediagnosis_test.go @@ -5,10 +5,10 @@ import ( "time" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/electricalconnection.go b/features/internal/electricalconnection.go index 6688c918..02eeab00 100644 --- a/features/internal/electricalconnection.go +++ b/features/internal/electricalconnection.go @@ -2,9 +2,9 @@ package internal import ( "github.com/enbility/eebus-go/api" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type ElectricalConnectionCommon struct { diff --git a/features/internal/electricalconnection_test.go b/features/internal/electricalconnection_test.go index 75e81ae2..340d3c1d 100644 --- a/features/internal/electricalconnection_test.go +++ b/features/internal/electricalconnection_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/helper_test.go b/features/internal/helper_test.go index d84b0653..442be090 100644 --- a/features/internal/helper_test.go +++ b/features/internal/helper_test.go @@ -5,11 +5,11 @@ import ( "sync" "time" - "github.com/enbility/eebus-go/util" shipapi "github.com/enbility/ship-go/api" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" ) diff --git a/features/internal/identification_test.go b/features/internal/identification_test.go index 85a18159..ad23af98 100644 --- a/features/internal/identification_test.go +++ b/features/internal/identification_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/incentivetable_test.go b/features/internal/incentivetable_test.go index c9917e55..ae9d7a65 100644 --- a/features/internal/incentivetable_test.go +++ b/features/internal/incentivetable_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/loadcontrol_test.go b/features/internal/loadcontrol_test.go index e6edffe8..e4339083 100644 --- a/features/internal/loadcontrol_test.go +++ b/features/internal/loadcontrol_test.go @@ -4,10 +4,10 @@ import ( "testing" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/measurement_test.go b/features/internal/measurement_test.go index 3e681c9f..293759b3 100644 --- a/features/internal/measurement_test.go +++ b/features/internal/measurement_test.go @@ -5,10 +5,10 @@ import ( "time" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/internal/timeseries_test.go b/features/internal/timeseries_test.go index 7d984454..755befb5 100644 --- a/features/internal/timeseries_test.go +++ b/features/internal/timeseries_test.go @@ -5,10 +5,10 @@ import ( "time" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" diff --git a/features/server/deviceconfiguration.go b/features/server/deviceconfiguration.go index 5020f257..42c8a5ed 100644 --- a/features/server/deviceconfiguration.go +++ b/features/server/deviceconfiguration.go @@ -5,10 +5,10 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" + "github.com/enbility/spine-go/util" ) type DeviceConfiguration struct { diff --git a/features/server/deviceconfiguration_test.go b/features/server/deviceconfiguration_test.go index 56ff39c2..c9a2a09b 100644 --- a/features/server/deviceconfiguration_test.go +++ b/features/server/deviceconfiguration_test.go @@ -6,13 +6,13 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/server" - eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/mocks" "github.com/enbility/eebus-go/service" - "github.com/enbility/eebus-go/util" "github.com/enbility/ship-go/cert" spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/mocks" + spinemocks "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -33,7 +33,7 @@ type DeviceConfigurationSuite struct { remoteDevice spineapi.DeviceRemoteInterface remoteEntity spineapi.EntityRemoteInterface - mockRemoteEntity *mocks.EntityRemoteInterface + mockRemoteEntity *spinemocks.EntityRemoteInterface } func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { @@ -44,16 +44,16 @@ func (s *DeviceConfigurationSuite) BeforeTest(suiteName, testName string) { []model.EntityTypeType{model.EntityTypeTypeCEM}, 9999, cert, 230.0, time.Second*4) - serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler := mocks.NewServiceReaderInterface(s.T()) serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() s.service = service.NewService(configuration, serviceHandler) _ = s.service.Setup() s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) - mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) - s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) - mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() diff --git a/features/server/devicediagnosis_test.go b/features/server/devicediagnosis_test.go index 9cf3f1bb..5d46dc47 100644 --- a/features/server/devicediagnosis_test.go +++ b/features/server/devicediagnosis_test.go @@ -6,13 +6,13 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/server" - eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/mocks" "github.com/enbility/eebus-go/service" - "github.com/enbility/eebus-go/util" "github.com/enbility/ship-go/cert" spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/mocks" + spinemocks "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -33,7 +33,7 @@ type DeviceDiagnosisSuite struct { remoteDevice spineapi.DeviceRemoteInterface remoteEntity spineapi.EntityRemoteInterface - mockRemoteEntity *mocks.EntityRemoteInterface + mockRemoteEntity *spinemocks.EntityRemoteInterface } func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { @@ -44,16 +44,16 @@ func (s *DeviceDiagnosisSuite) BeforeTest(suiteName, testName string) { []model.EntityTypeType{model.EntityTypeTypeCEM}, 9999, cert, 230.0, time.Second*4) - serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler := mocks.NewServiceReaderInterface(s.T()) serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() s.service = service.NewService(configuration, serviceHandler) _ = s.service.Setup() s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) - mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) - s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) - mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() diff --git a/features/server/electricalconnection.go b/features/server/electricalconnection.go index 688c74eb..0665d670 100644 --- a/features/server/electricalconnection.go +++ b/features/server/electricalconnection.go @@ -4,10 +4,10 @@ import ( "errors" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" + "github.com/enbility/spine-go/util" ) type ElectricalConnection struct { diff --git a/features/server/electricalconnection_test.go b/features/server/electricalconnection_test.go index 0d84afac..650ae95e 100644 --- a/features/server/electricalconnection_test.go +++ b/features/server/electricalconnection_test.go @@ -6,13 +6,13 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/server" - eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/mocks" "github.com/enbility/eebus-go/service" - "github.com/enbility/eebus-go/util" "github.com/enbility/ship-go/cert" spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/mocks" + spinemocks "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -33,7 +33,7 @@ type ElectricalConnectionSuite struct { remoteDevice spineapi.DeviceRemoteInterface remoteEntity spineapi.EntityRemoteInterface - mockRemoteEntity *mocks.EntityRemoteInterface + mockRemoteEntity *spinemocks.EntityRemoteInterface } func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { @@ -44,16 +44,16 @@ func (s *ElectricalConnectionSuite) BeforeTest(suiteName, testName string) { []model.EntityTypeType{model.EntityTypeTypeCEM}, 9999, cert, 230.0, time.Second*4) - serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler := mocks.NewServiceReaderInterface(s.T()) serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() s.service = service.NewService(configuration, serviceHandler) _ = s.service.Setup() s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) - mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) - s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) - mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() diff --git a/features/server/helper_test.go b/features/server/helper_test.go index 58c04157..142e2a82 100644 --- a/features/server/helper_test.go +++ b/features/server/helper_test.go @@ -5,11 +5,11 @@ import ( "testing" "github.com/enbility/eebus-go/api" - "github.com/enbility/eebus-go/util" shipmocks "github.com/enbility/ship-go/mocks" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" "github.com/enbility/spine-go/spine" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/mock" ) diff --git a/features/server/loadcontrol.go b/features/server/loadcontrol.go index b3524e3f..9cc41f73 100644 --- a/features/server/loadcontrol.go +++ b/features/server/loadcontrol.go @@ -5,9 +5,9 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type LoadControl struct { diff --git a/features/server/loadcontrol_test.go b/features/server/loadcontrol_test.go index ec3bea3a..57492f6a 100644 --- a/features/server/loadcontrol_test.go +++ b/features/server/loadcontrol_test.go @@ -6,13 +6,13 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/server" - eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/mocks" "github.com/enbility/eebus-go/service" - "github.com/enbility/eebus-go/util" "github.com/enbility/ship-go/cert" spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/mocks" + spinemocks "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -33,7 +33,7 @@ type LoadControlSuite struct { remoteDevice spineapi.DeviceRemoteInterface remoteEntity spineapi.EntityRemoteInterface - mockRemoteEntity *mocks.EntityRemoteInterface + mockRemoteEntity *spinemocks.EntityRemoteInterface } func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { @@ -44,16 +44,16 @@ func (s *LoadControlSuite) BeforeTest(suiteName, testName string) { []model.EntityTypeType{model.EntityTypeTypeCEM}, 9999, cert, 230.0, time.Second*4) - serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler := mocks.NewServiceReaderInterface(s.T()) serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() s.service = service.NewService(configuration, serviceHandler) _ = s.service.Setup() s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) - mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) - s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) - mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() diff --git a/features/server/measurement.go b/features/server/measurement.go index 3c73a1b5..5a8a7cc7 100644 --- a/features/server/measurement.go +++ b/features/server/measurement.go @@ -5,9 +5,9 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/internal" - "github.com/enbility/eebus-go/util" spineapi "github.com/enbility/spine-go/api" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" ) type Measurement struct { diff --git a/features/server/measurement_test.go b/features/server/measurement_test.go index 55f446bd..6f424faf 100644 --- a/features/server/measurement_test.go +++ b/features/server/measurement_test.go @@ -6,13 +6,13 @@ import ( "github.com/enbility/eebus-go/api" "github.com/enbility/eebus-go/features/server" - eebusmocks "github.com/enbility/eebus-go/mocks" + "github.com/enbility/eebus-go/mocks" "github.com/enbility/eebus-go/service" - "github.com/enbility/eebus-go/util" "github.com/enbility/ship-go/cert" spineapi "github.com/enbility/spine-go/api" - "github.com/enbility/spine-go/mocks" + spinemocks "github.com/enbility/spine-go/mocks" "github.com/enbility/spine-go/model" + "github.com/enbility/spine-go/util" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" @@ -33,7 +33,7 @@ type MeasurementSuite struct { remoteDevice spineapi.DeviceRemoteInterface remoteEntity spineapi.EntityRemoteInterface - mockRemoteEntity *mocks.EntityRemoteInterface + mockRemoteEntity *spinemocks.EntityRemoteInterface } func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { @@ -44,16 +44,16 @@ func (s *MeasurementSuite) BeforeTest(suiteName, testName string) { []model.EntityTypeType{model.EntityTypeTypeCEM}, 9999, cert, 230.0, time.Second*4) - serviceHandler := eebusmocks.NewServiceReaderInterface(s.T()) + serviceHandler := mocks.NewServiceReaderInterface(s.T()) serviceHandler.EXPECT().ServicePairingDetailUpdate(mock.Anything, mock.Anything).Return().Maybe() s.service = service.NewService(configuration, serviceHandler) _ = s.service.Setup() s.localEntity = s.service.LocalDevice().EntityForType(model.EntityTypeTypeCEM) - mockRemoteDevice := mocks.NewDeviceRemoteInterface(s.T()) - s.mockRemoteEntity = mocks.NewEntityRemoteInterface(s.T()) - mockRemoteFeature := mocks.NewFeatureRemoteInterface(s.T()) + mockRemoteDevice := spinemocks.NewDeviceRemoteInterface(s.T()) + s.mockRemoteEntity = spinemocks.NewEntityRemoteInterface(s.T()) + mockRemoteFeature := spinemocks.NewFeatureRemoteInterface(s.T()) mockRemoteDevice.EXPECT().FeatureByEntityTypeAndRole(mock.Anything, mock.Anything, mock.Anything).Return(mockRemoteFeature).Maybe() mockRemoteDevice.EXPECT().Ski().Return(remoteSki).Maybe() s.mockRemoteEntity.EXPECT().Device().Return(mockRemoteDevice).Maybe() diff --git a/util/ptr.go b/util/ptr.go deleted file mode 100644 index e82ce5d7..00000000 --- a/util/ptr.go +++ /dev/null @@ -1,5 +0,0 @@ -package util - -func Ptr[T any](v T) *T { - return &v -}