Skip to content

Commit

Permalink
PageAcInModel: add power factor
Browse files Browse the repository at this point in the history
  • Loading branch information
martinbosma committed Dec 17, 2024
1 parent 3470667 commit 95d6dfe
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pages/settings/devicelist/ac-in/PageAcInModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ ObjectModel {
Repeater {
model: root.phaseNumbers
delegate: ListQuantityGroup {
allowed: root.phaseCountKnown || (phaseVoltage.isValid || phaseCurrent.isValid || phasePower.isValid)
allowed: root.phaseCountKnown || (phaseVoltage.isValid || phaseCurrent.isValid ||
phasePower.isValid || phasePowerFactor.isValid)
text: CommonWords.ac_phase_x.arg(modelData)
textModel: [
{ value: phaseVoltage.value, unit: VenusOS.Units_Volt_AC },
{ value: phaseCurrent.value, unit: VenusOS.Units_Amp },
{ value: phasePower.value, unit: VenusOS.Units_Watt },
{ value: phasePowerFactor.value, unit: VenusOS.Units_PowerFactor,
visible: phasePowerFactor.isValid },
]

VeQuickItem {
Expand All @@ -69,6 +72,10 @@ ObjectModel {
id: phasePower
uid: root.bindPrefix + "/Ac/L" + modelData + "/Power"
}
VeQuickItem {
id: phasePowerFactor
uid: root.bindPrefix + "/Ac/L" + modelData + "/PowerFactor"
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class Enums : public QObject
Units_Hectopascal,
Units_Kilopascal,
Units_CardinalDirection,
Units_PowerFactor
};
Q_ENUM(Units_Type)

Expand Down
4 changes: 4 additions & 0 deletions src/units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ int Units::defaultUnitPrecision(VenusOS::Enums::Units_Type unit) const
{
switch (unit) {
case VenusOS::Enums::Units_Energy_KiloWattHour: return 3;
case VenusOS::Enums::Units_PowerFactor: return 3;
case VenusOS::Enums::Units_Volume_CubicMeter: return 3;
case VenusOS::Enums::Units_Volt_DC: return 2;
case VenusOS::Enums::Units_Volt_AC: // fall through
Expand Down Expand Up @@ -154,6 +155,8 @@ QString Units::defaultUnitString(VenusOS::Enums::Units_Type unit, int formatHint
return QStringLiteral("kPa");
case VenusOS::Enums::Units_CardinalDirection:
return DegreesSymbol;
case VenusOS::Enums::Units_PowerFactor:
return QString();
default:
qWarning() << "No unit label known for unit:" << unit;
return QString();
Expand Down Expand Up @@ -202,6 +205,7 @@ bool Units::isScalingSupported(VenusOS::Enums::Units_Type unit) const
case VenusOS::Enums::Units_Hectopascal:
case VenusOS::Enums::Units_Kilopascal:
case VenusOS::Enums::Units_CardinalDirection:
case VenusOS::Enums::Units_PowerFactor:
default:
return false;
}
Expand Down
19 changes: 19 additions & 0 deletions tests/units/tst_units.qml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,25 @@ TestCase {
expect(VenusOS.Units_CardinalDirection, 23.6, "24", "° direction_northeast")
}

function test_powerFactor() {
expect(VenusOS.Units_PowerFactor, NaN, "--", "")
expect(VenusOS.Units_PowerFactor, -1234, "-1234", "")
expect(VenusOS.Units_PowerFactor, -100, "-100.0", "")
expect(VenusOS.Units_PowerFactor, -15.55, "-15.55", "")
expect(VenusOS.Units_PowerFactor, -1, "-1.000", "")
expect(VenusOS.Units_PowerFactor, -0.255, "-0.255", "")
expect(VenusOS.Units_PowerFactor, -0.25, "-0.250", "")
expect(VenusOS.Units_PowerFactor, -0.1, "-0.100", "")
expect(VenusOS.Units_PowerFactor, 0, "0.000", "")
expect(VenusOS.Units_PowerFactor, 0.1, "0.100", "")
expect(VenusOS.Units_PowerFactor, 0.25, "0.250", "")
expect(VenusOS.Units_PowerFactor, 0.255, "0.255", "")
expect(VenusOS.Units_PowerFactor, 1, "1.000", "")
expect(VenusOS.Units_PowerFactor, 15.55, "15.55", "")
expect(VenusOS.Units_PowerFactor, 100, "100.0", "")
expect(VenusOS.Units_PowerFactor, 1234, "1234", "")
}

function test_precisionZero() {
var units = [VenusOS.Units_Volume_Liter,
VenusOS.Units_Volume_GallonImperial,
Expand Down

0 comments on commit 95d6dfe

Please sign in to comment.