From f32da529bfd0cde43a4ccf98d80be6bc75fa44b9 Mon Sep 17 00:00:00 2001 From: Daniel McInnes Date: Thu, 20 Jun 2024 14:18:13 +1000 Subject: [PATCH] Fix bug in AC input power calculation Specific to AC inputs on Multi RS systems --- data/common/AcInputPhaseModel.qml | 4 ---- data/common/AcInputServiceLoader.qml | 9 --------- data/common/ActiveAcInput.qml | 28 ++++++++++++---------------- 3 files changed, 12 insertions(+), 29 deletions(-) diff --git a/data/common/AcInputPhaseModel.qml b/data/common/AcInputPhaseModel.qml index 7e3182e05..d067dfb40 100644 --- a/data/common/AcInputPhaseModel.qml +++ b/data/common/AcInputPhaseModel.qml @@ -9,8 +9,6 @@ import Victron.VenusOS ListModel { id: root - signal phaseValueChanged(int phaseIndex, string propertyName, real propertyValue) - readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled property Instantiator _phaseObjects: Instantiator { @@ -25,7 +23,6 @@ ListModel { onClampedCurrentValueChanged: { if (model.index >= 0 && model.index < root.count) { setProperty(model.index, "current", clampedCurrentValue) - root.phaseValueChanged(model.index, "current", clampedCurrentValue) } } } @@ -39,7 +36,6 @@ ListModel { onClampedPowerValueChanged: { if (model.index >= 0 && model.index < root.count) { setProperty(model.index, "power", clampedPowerValue) - root.phaseValueChanged(model.index, "power", clampedPowerValue) } } } diff --git a/data/common/AcInputServiceLoader.qml b/data/common/AcInputServiceLoader.qml index 3e2f5c957..ac2744ec4 100644 --- a/data/common/AcInputServiceLoader.qml +++ b/data/common/AcInputServiceLoader.qml @@ -12,11 +12,6 @@ Loader { property string serviceUid property string serviceType - readonly property real totalPower: (!hasTotalPower || !item) ? NaN - : isNaN(_itemPower) ? NaN - : _feedbackEnabled ? _itemPower - : _itemPower > 0 ? _itemPower // see AcInputs.clampMeasurement() - : 0.0 readonly property bool hasTotalPower: serviceType === "vebus" || serviceType == "grid" || serviceType == "genset" readonly property real currentLimit: !!item ? item.currentLimit : NaN @@ -29,10 +24,6 @@ Loader { readonly property bool _feedbackEnabled: Global.systemSettings.essFeedbackToGridEnabled - readonly property real _itemPower: !item ? 0.0 - : item.power === undefined ? NaN - : item.power - sourceComponent: { if (serviceUid == "" || serviceType == "") { return null diff --git a/data/common/ActiveAcInput.qml b/data/common/ActiveAcInput.qml index 0a830cb6a..9219b46ad 100644 --- a/data/common/ActiveAcInput.qml +++ b/data/common/ActiveAcInput.qml @@ -18,7 +18,7 @@ Device { readonly property int source: !!inputInfo ? inputInfo.source : VenusOS.AcInputs_InputSource_NotAvailable readonly property alias gensetStatusCode: _acInputService.gensetStatusCode - readonly property real power: _acInputService.hasTotalPower ? _acInputService.totalPower : _phases.totalPower + readonly property real power: _phases.totalPower readonly property real current: phases.count === 1 ? _phases.firstPhaseCurrent : NaN // multi-phase systems don't have a total current readonly property alias currentLimit: _acInputService.currentLimit readonly property alias phases: _phases @@ -27,23 +27,19 @@ Device { readonly property AcInputPhaseModel _phases: AcInputPhaseModel { id: _phases - property real totalPower: NaN - property real firstPhaseCurrent: NaN + property int totalPower + property real firstPhaseCurrent: count === 1 ? get(0).current : NaN - onPhaseValueChanged: function(phaseIndex, propertyName, propertyValue) { - if (propertyName === "power" && !root._acInputService.hasTotalPower) { - let total = NaN - for (let i = 0; i < phases.count; ++i) { - if (i === phaseIndex) { - total = Units.sumRealNumbers(total, propertyValue) - } else { - const phase = get(phaseIndex) - total = Units.sumRealNumbers(total, phase ? phase[propertyName] : NaN) - } + readonly property Timer _timer: Timer { // timer needed so the display doesn't update too frequently + interval: 1000 + repeat: true + running: true + onTriggered: { + let sum = 0 + for (let i = 0; i < _phases.count; ++i) { + sum += _phases.get(i).power || 0 } - totalPower = total - } else if (propertyName === "current" && count === 1) { - firstPhaseCurrent = propertyValue + _phases.totalPower = sum } } }