From 13fb6efa7699e56b59fe75a5f3c69073f2b2d969 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Sun, 2 Feb 2025 11:45:00 +1000 Subject: [PATCH] Change PagePowerDebug to use QuantityTable and load in mock mode Use QuantityTable as ListTextGroup will be obsoleted. Use BackendConnection.uidPrefix() to load the page in mock mode. Part of #1338 --- pages/settings/debug/PagePowerDebug.qml | 111 ++++++++++-------------- 1 file changed, 44 insertions(+), 67 deletions(-) diff --git a/pages/settings/debug/PagePowerDebug.qml b/pages/settings/debug/PagePowerDebug.qml index 33fc9ee1f..53ac51141 100644 --- a/pages/settings/debug/PagePowerDebug.qml +++ b/pages/settings/debug/PagePowerDebug.qml @@ -9,25 +9,16 @@ import Victron.VenusOS Page { id: root - property string qwacsPvInverterPrefix: "com.victronenergy.pvinverter.qwacs_di1" - property string sensorsPvInverterPrefix: "com.victronenergy.pvinverter.vebusacsensor_output" + property string qwacsPvInverterPrefix: "%1/com.victronenergy.pvinverter.qwacs_di1".arg(BackendConnection.uidPrefix()) + property string sensorsPvInverterPrefix: "%1/com.victronenergy.pvinverter.vebusacsensor_output".arg(BackendConnection.uidPrefix()) property string vebusPrefix: Global.system.veBus.serviceUid function powerDiff(a, b) { - if (!a.isValid || !b.isValid) - return "--" - return Units.formatNumber(a.value - b.value) + "W" + return a.isValid && !b.isValid ? a.value - b.value : NaN } - function apparentPower(V, I) { - if (!V.isValid || !I.isValid) - return "--" - return Units.formatNumber(V.value * I.value) + "VA" - } - - function groupItemWidth(group) { - const columnCount = 7 - return (group.availableWidth - (group.content.spacing * (columnCount - 1))) / columnCount + function apparentPower(voltage, current) { + return voltage.isValid && !current.isValid ? voltage.value * current.value : NaN } QtObject { @@ -50,9 +41,9 @@ Page { property VeQuickItem voltageL1: VeQuickItem { uid: qwacsPvInverterPrefix + "/Ac/L1/Voltage" } property VeQuickItem voltageL2: VeQuickItem { uid: qwacsPvInverterPrefix + "/Ac/L2/Voltage" } property VeQuickItem voltageL3: VeQuickItem { uid: qwacsPvInverterPrefix + "/Ac/L3/Voltage" } - property string apparentL1: apparentPower(currentL1, voltageL1) - property string apparentL2: apparentPower(currentL2, voltageL2) - property string apparentL3: apparentPower(currentL3, voltageL3) + property real apparentL1: apparentPower(currentL1, voltageL1) + property real apparentL2: apparentPower(currentL2, voltageL2) + property real apparentL3: apparentPower(currentL3, voltageL3) } QtObject { @@ -66,6 +57,13 @@ Page { property VeQuickItem apparentL3: VeQuickItem { uid: vebusPrefix + "/Ac/Out/L3/S" } } + QtObject { + id: diffs + readonly property real powerL1: root.powerDiff(sensorPvInverter.powerL1, qwacsPvInverter.powerL1) + readonly property real powerL2: root.powerDiff(sensorPvInverter.powerL2, qwacsPvInverter.powerL2) + readonly property real powerL3: root.powerDiff(sensorPvInverter.powerL3, qwacsPvInverter.powerL3) + } + GradientListView { // This page has no useful data on MQTT. This can be resolved later on if the MQTT // equivalents can be identified for the com.victronenergy.pvinverter.qwacs_di1 and @@ -84,57 +82,36 @@ Page { VisibleItemModel { id: validModel - ListTextGroup { - id: groupP - - itemWidth: root.groupItemWidth(groupP) - text: "P" - textModel: [ "AC Out", "AC Out", "Qwacs", "Qwacs", "Sensors", "Diff" ] - } - - ListTextGroup { - id: groupL1 - - text: "L1" - itemWidth: root.groupItemWidth(groupL1) - textModel: [ - acOut.powerL1.value || "--", - acOut.apparentL1.value || "--", - qwacsPvInverter.powerL1.value || "--", - qwacsPvInverter.apparentL1.value || "--", - sensorPvInverter.powerL1.value || "--", - powerDiff(sensorPvInverter.powerL1, qwacsPvInverter.powerL1), - ] - } - - ListTextGroup { - id: groupL2 - - text: "L2" - itemWidth: root.groupItemWidth(groupL2) - textModel: [ - acOut.powerL2.value || "--", - acOut.apparentL2.value || "--", - qwacsPvInverter.powerL2.value || "--", - qwacsPvInverter.apparentL2.value || "--", - sensorPvInverter.powerL2.value || "--", - powerDiff(sensorPvInverter.powerL2, qwacsPvInverter.powerL2), - ] - } - - ListTextGroup { - id: groupL3 - - text: "L3" - itemWidth: root.groupItemWidth(groupL3) - textModel: [ - acOut.powerL3.value || "--", - acOut.apparentL3.value || "--", - qwacsPvInverter.powerL3.value || "--", - qwacsPvInverter.apparentL3.value || "--", - sensorPvInverter.powerL3.value || "--", - powerDiff(sensorPvInverter.powerL3, qwacsPvInverter.powerL3), + QuantityTable { + rowCount: 3 + units: [ + { title: "Name", unit: VenusOS.Units_None }, + { title: "AC Out", unit: VenusOS.Units_Watt }, + { title: "AC Out", unit: VenusOS.Units_VoltAmpere }, + { title: "Qwacs", unit: VenusOS.Units_Watt }, + { title: "Qwacs", unit: VenusOS.Units_VoltAmpere }, + { title: "Sensors", unit: VenusOS.Units_Watt }, + { title: "Diff", unit: VenusOS.Units_Watt }, ] + valueForModelIndex: function(phaseIndex, column) { + const phaseName = `L${phaseIndex + 1}` + switch (column) { + case 0: + return phaseName + case 1: + return acOut[`power${phaseName}`] + case 2: + return acOut[`apparent${phaseName}`] + case 3: + return qwacsPvInverter[`power${phaseName}`] + case 4: + return qwacsPvInverter[`apparent${phaseName}`] + case 5: + return sensorPvInverter[`power${phaseName}`] + case 6: + return diffs[`power${phaseName}`] + } + } } } }