@@ -258,15 +258,27 @@ Public Class UPS_Device
258
258
LogFile.LogException(ex, Me )
259
259
End If
260
260
End Try
261
+ Try
262
+ Dim value = Single .Parse(GetUPSVar( "output.realpower" ), INVARIANT_CULTURE)
263
+ .Output_Power = value
264
+ LogFile.LogTracing( "output.power: " & value, LogLvl.LOG_DEBUG, Me )
265
+ Catch ex As Exception
266
+
267
+ End Try
261
268
End With
262
269
263
270
' Determine optimal method for measuring power output from the UPS.
264
271
LogFile.LogTracing( "Determining best method to calculate power usage..." , LogLvl.LOG_NOTICE, Me )
265
272
' Start with directly reading a variable from the UPS.
266
273
Try
267
- GetUPSVar( "ups.realpower" )
268
- _PowerCalculationMethod = PowerMethod.RealPower
269
- LogFile.LogTracing( "Using RealPower method." , LogLvl.LOG_NOTICE, Me )
274
+ If freshData.UPS_Value.Output_Power <> Nothing Then
275
+ _PowerCalculationMethod = PowerMethod.RealOutputPower
276
+ LogFile.LogTracing( "Using RealOutputPower method." , LogLvl.LOG_NOTICE, Me )
277
+ Else
278
+ GetUPSVar( "ups.realpower" )
279
+ _PowerCalculationMethod = PowerMethod.RealPower
280
+ LogFile.LogTracing( "Using RealPower method." , LogLvl.LOG_NOTICE, Me )
281
+ End If
270
282
Catch
271
283
Try
272
284
GetUPSVar( "ups.realpower.nominal" )
@@ -327,6 +339,9 @@ Public Class UPS_Device
327
339
Case PowerMethod.RealPower
328
340
parsedValue = Double .Parse(GetUPSVar( "ups.realpower" ), INVARIANT_CULTURE)
329
341
342
+ Case PowerMethod.RealOutputPower
343
+ parsedValue = Single .Parse(GetUPSVar( "output.realpower" ), INVARIANT_CULTURE)
344
+
330
345
Case PowerMethod.RPNomLoadPct
331
346
parsedValue = Double .Parse(GetUPSVar( "ups.realpower.nominal" ), INVARIANT_CULTURE)
332
347
parsedValue *= UPS_Datas.UPS_Value.Load / 100.0
@@ -336,13 +351,13 @@ Public Class UPS_Device
336
351
Dim nomVoltage = Double .Parse(GetUPSVar( "input.voltage.nominal" ), INVARIANT_CULTURE)
337
352
338
353
parsedValue = nomCurrent * nomVoltage * POWER_FACTOR
339
- parsedValue = UPS_Datas.UPS_Value.Load / 100.0
354
+ parsedValue * = UPS_Datas.UPS_Value.Load / 100.0
340
355
Case PowerMethod.OutputVACalc
341
356
.Output_Current = Single .Parse(GetUPSVar( "output.current" ), INVARIANT_CULTURE)
342
357
parsedValue = .Output_Current * .Output_Voltage * POWER_FACTOR
343
358
Case Else
344
359
' Should not trigger - something has gone wrong.
345
- Throw New InvalidOperationException( "Insufficient variables to calculate power." )
360
+ Throw New InvalidOperationException( "Reached Else case when attempting to get power output for method " & _PowerCalculationMethod )
346
361
End Select
347
362
Catch ex As FormatException
348
363
LogFile.LogTracing( "Unexpected format trying to parse value from UPS. Exception:" , LogLvl.LOG_ERROR, Me )
@@ -352,7 +367,9 @@ Public Class UPS_Device
352
367
LogFile.LogException(ex, Me )
353
368
End Try
354
369
355
- .Output_Power = parsedValue
370
+ ' Apply rounding to this number since calculations have extended to three decimal places.
371
+ ' TODO: Remove this round function once gauges can handle decimal places better.
372
+ .Output_Power = Math.Round(parsedValue, 1 )
356
373
End If
357
374
358
375
' Handle out-of-range battery charge
0 commit comments