Skip to content

Commit 4ab53c1

Browse files
committed
Adding RealOutputPower calc method, small fixes
- Adding the `RealOutputPower` calculation method for UPS power output, specifically for Huawei UPSes. - Corrected mistake in `InputNomVALoadPct` calculation method that omitted a multiplication - Make error more clear if execution ever reaches Else case in power calculation switch statement.
1 parent a068ddb commit 4ab53c1

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

WinNUT_V2/WinNUT-Client_Common/Common_Enums.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ End Enum
124124
Public Enum PowerMethod
125125
Unavailable ' No methods are available to calculate power.
126126
RealPower ' The ups.realpower variable is available for direct reading.
127+
RealOutputPower ' output.realpower is available for direct reading.
127128
RPNomLoadPct ' Power is calcualted as the load percentage of nominal realpower.
128129
InputNomVALoadPct ' Power is given as the nominal power calculated from nominal input volts/amps (and PF), multiplied by the percent load.
129130
OutputVACalc ' Power is calculated with output voltage and current (seen on Huawei, issue #150)

WinNUT_V2/WinNUT-Client_Common/UPS_Device.vb

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,27 @@ Public Class UPS_Device
258258
LogFile.LogException(ex, Me)
259259
End If
260260
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
261268
End With
262269

263270
' Determine optimal method for measuring power output from the UPS.
264271
LogFile.LogTracing("Determining best method to calculate power usage...", LogLvl.LOG_NOTICE, Me)
265272
' Start with directly reading a variable from the UPS.
266273
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
270282
Catch
271283
Try
272284
GetUPSVar("ups.realpower.nominal")
@@ -327,6 +339,9 @@ Public Class UPS_Device
327339
Case PowerMethod.RealPower
328340
parsedValue = Double.Parse(GetUPSVar("ups.realpower"), INVARIANT_CULTURE)
329341

342+
Case PowerMethod.RealOutputPower
343+
parsedValue = Single.Parse(GetUPSVar("output.realpower"), INVARIANT_CULTURE)
344+
330345
Case PowerMethod.RPNomLoadPct
331346
parsedValue = Double.Parse(GetUPSVar("ups.realpower.nominal"), INVARIANT_CULTURE)
332347
parsedValue *= UPS_Datas.UPS_Value.Load / 100.0
@@ -336,13 +351,13 @@ Public Class UPS_Device
336351
Dim nomVoltage = Double.Parse(GetUPSVar("input.voltage.nominal"), INVARIANT_CULTURE)
337352

338353
parsedValue = nomCurrent * nomVoltage * POWER_FACTOR
339-
parsedValue = UPS_Datas.UPS_Value.Load / 100.0
354+
parsedValue *= UPS_Datas.UPS_Value.Load / 100.0
340355
Case PowerMethod.OutputVACalc
341356
.Output_Current = Single.Parse(GetUPSVar("output.current"), INVARIANT_CULTURE)
342357
parsedValue = .Output_Current * .Output_Voltage * POWER_FACTOR
343358
Case Else
344359
' 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)
346361
End Select
347362
Catch ex As FormatException
348363
LogFile.LogTracing("Unexpected format trying to parse value from UPS. Exception:", LogLvl.LOG_ERROR, Me)
@@ -352,7 +367,9 @@ Public Class UPS_Device
352367
LogFile.LogException(ex, Me)
353368
End Try
354369

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)
356373
End If
357374

358375
' Handle out-of-range battery charge

0 commit comments

Comments
 (0)