@@ -15,18 +15,14 @@ import (
15
15
// return the current power limitation factor
16
16
//
17
17
// possible errors:
18
- // - ErrDataNotAvailable if no such limit is (yet) available
18
+ // - ErrDataNotAvailable if no such value is (yet) available
19
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
19
20
// - and others
20
21
func (e * MGCP ) PowerLimitationFactor (entity spineapi.EntityRemoteInterface ) (float64 , error ) {
21
22
if ! e .IsCompatibleEntityType (entity ) {
22
23
return 0 , api .ErrNoCompatibleEntity
23
24
}
24
25
25
- measurement , err := client .NewMeasurement (e .LocalEntity , entity )
26
- if err != nil || measurement == nil {
27
- return 0 , err
28
- }
29
-
30
26
keyname := model .DeviceConfigurationKeyNameTypePvCurtailmentLimitFactor
31
27
32
28
deviceConfiguration , err := client .NewDeviceConfiguration (e .LocalEntity , entity )
@@ -58,6 +54,11 @@ func (e *MGCP) PowerLimitationFactor(entity spineapi.EntityRemoteInterface) (flo
58
54
//
59
55
// - positive values are used for consumption
60
56
// - negative values are used for production
57
+ //
58
+ // possible errors:
59
+ // - ErrDataNotAvailable if no such value is (yet) available
60
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
61
+ // - and others
61
62
func (e * MGCP ) Power (entity spineapi.EntityRemoteInterface ) (float64 , error ) {
62
63
if ! e .IsCompatibleEntityType (entity ) {
63
64
return 0 , api .ErrNoCompatibleEntity
@@ -69,7 +70,11 @@ func (e *MGCP) Power(entity spineapi.EntityRemoteInterface) (float64, error) {
69
70
ScopeType : util .Ptr (model .ScopeTypeTypeACPowerTotal ),
70
71
}
71
72
data , err := internal .MeasurementPhaseSpecificDataForFilter (e .LocalEntity , entity , filter , model .EnergyDirectionTypeConsume , nil )
72
- if err != nil || len (data ) != 1 {
73
+ if err != nil {
74
+ return 0 , err
75
+ }
76
+
77
+ if len (data ) != 1 {
73
78
return 0 , api .ErrDataNotAvailable
74
79
}
75
80
@@ -81,6 +86,11 @@ func (e *MGCP) Power(entity spineapi.EntityRemoteInterface) (float64, error) {
81
86
// return the total feed in energy at the grid connection point
82
87
//
83
88
// - negative values are used for production
89
+ //
90
+ // possible errors:
91
+ // - ErrDataNotAvailable if no such value is (yet) available
92
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
93
+ // - and others
84
94
func (e * MGCP ) EnergyFeedIn (entity spineapi.EntityRemoteInterface ) (float64 , error ) {
85
95
if ! e .IsCompatibleEntityType (entity ) {
86
96
return 0 , api .ErrNoCompatibleEntity
@@ -100,6 +110,13 @@ func (e *MGCP) EnergyFeedIn(entity spineapi.EntityRemoteInterface) (float64, err
100
110
if err != nil || len (result ) == 0 || result [0 ].Value == nil {
101
111
return 0 , api .ErrDataNotAvailable
102
112
}
113
+
114
+ // if the value state is set and not normal, the value is not valid and should be ignored
115
+ // therefore we return an error
116
+ if result [0 ].ValueState != nil && * result [0 ].ValueState != model .MeasurementValueStateTypeNormal {
117
+ return 0 , api .ErrDataInvalid
118
+ }
119
+
103
120
return result [0 ].Value .GetValue (), nil
104
121
}
105
122
@@ -108,6 +125,11 @@ func (e *MGCP) EnergyFeedIn(entity spineapi.EntityRemoteInterface) (float64, err
108
125
// return the total consumption energy at the grid connection point
109
126
//
110
127
// - positive values are used for consumption
128
+ //
129
+ // possible errors:
130
+ // - ErrDataNotAvailable if no such value is (yet) available
131
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
132
+ // - and others
111
133
func (e * MGCP ) EnergyConsumed (entity spineapi.EntityRemoteInterface ) (float64 , error ) {
112
134
if ! e .IsCompatibleEntityType (entity ) {
113
135
return 0 , api .ErrNoCompatibleEntity
@@ -127,6 +149,13 @@ func (e *MGCP) EnergyConsumed(entity spineapi.EntityRemoteInterface) (float64, e
127
149
if err != nil || len (result ) == 0 || result [0 ].Value == nil {
128
150
return 0 , api .ErrDataNotAvailable
129
151
}
152
+
153
+ // if the value state is set and not normal, the value is not valid and should be ignored
154
+ // therefore we return an error
155
+ if result [0 ].ValueState != nil && * result [0 ].ValueState != model .MeasurementValueStateTypeNormal {
156
+ return 0 , api .ErrDataInvalid
157
+ }
158
+
130
159
return result [0 ].Value .GetValue (), nil
131
160
}
132
161
@@ -136,6 +165,11 @@ func (e *MGCP) EnergyConsumed(entity spineapi.EntityRemoteInterface) (float64, e
136
165
//
137
166
// - positive values are used for consumption
138
167
// - negative values are used for production
168
+ //
169
+ // possible errors:
170
+ // - ErrDataNotAvailable if no such value is (yet) available
171
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
172
+ // - and others
139
173
func (e * MGCP ) CurrentPerPhase (entity spineapi.EntityRemoteInterface ) ([]float64 , error ) {
140
174
if ! e .IsCompatibleEntityType (entity ) {
141
175
return nil , api .ErrNoCompatibleEntity
@@ -152,6 +186,11 @@ func (e *MGCP) CurrentPerPhase(entity spineapi.EntityRemoteInterface) ([]float64
152
186
// Scenario 6
153
187
154
188
// return the voltage phase details at the grid connection point
189
+ //
190
+ // possible errors:
191
+ // - ErrDataNotAvailable if no such value is (yet) available
192
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
193
+ // - and others
155
194
func (e * MGCP ) VoltagePerPhase (entity spineapi.EntityRemoteInterface ) ([]float64 , error ) {
156
195
if ! e .IsCompatibleEntityType (entity ) {
157
196
return nil , api .ErrNoCompatibleEntity
@@ -168,6 +207,11 @@ func (e *MGCP) VoltagePerPhase(entity spineapi.EntityRemoteInterface) ([]float64
168
207
// Scenario 7
169
208
170
209
// return frequency at the grid connection point
210
+ //
211
+ // possible errors:
212
+ // - ErrDataNotAvailable if no such value is (yet) available
213
+ // - ErrDataInvalid if the currently available data is invalid and should be ignored
214
+ // - and others
171
215
func (e * MGCP ) Frequency (entity spineapi.EntityRemoteInterface ) (float64 , error ) {
172
216
if ! e .IsCompatibleEntityType (entity ) {
173
217
return 0 , api .ErrNoCompatibleEntity
@@ -187,5 +231,12 @@ func (e *MGCP) Frequency(entity spineapi.EntityRemoteInterface) (float64, error)
187
231
if err != nil || len (result ) == 0 || result [0 ].Value == nil {
188
232
return 0 , api .ErrDataNotAvailable
189
233
}
234
+
235
+ // if the value state is set and not normal, the value is not valid and should be ignored
236
+ // therefore we return an error
237
+ if result [0 ].ValueState != nil && * result [0 ].ValueState != model .MeasurementValueStateTypeNormal {
238
+ return 0 , api .ErrDataInvalid
239
+ }
240
+
190
241
return result [0 ].Value .GetValue (), nil
191
242
}
0 commit comments