From a51ad733f276385e55d25ac92c9cc4092209e1da Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Thu, 19 Dec 2024 10:27:17 +1000 Subject: [PATCH] Move startstop1 uid finding feature into a separate component This is a general cleanup to make it clear how to reuse this functionality from elsewhere if that is needed. --- CMakeLists.txt | 1 + components/GensetStartStop1Finder.qml | 62 +++++++++++++++++++++++++++ components/PageGensetModel.qml | 28 +++--------- 3 files changed, 68 insertions(+), 23 deletions(-) create mode 100644 components/GensetStartStop1Finder.qml diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cc657130..a8e7d2528 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,6 +207,7 @@ set (VENUS_QML_MODULE_SOURCES components/GaugeModel.qml components/GaugeHeader.qml components/GeneratorManualControlButton.qml + components/GensetStartStop1Finder.qml components/EvChargerStatusModel.qml components/FlatListItemSeparator.qml components/GeneratorIconLabel.qml diff --git a/components/GensetStartStop1Finder.qml b/components/GensetStartStop1Finder.qml new file mode 100644 index 000000000..b8ad189aa --- /dev/null +++ b/components/GensetStartStop1Finder.qml @@ -0,0 +1,62 @@ +/* +** Copyright (C) 2024 Victron Energy B.V. +** See LICENSE.txt for license information. +*/ + +import QtQuick +import Victron.VenusOS + +/* + This component provides a way to find the startstop1 uid for a genset service. + On D-Bus this is always "com.victronenergy.generator.startstop1", but on a MQTT backend this + is less easily located. + + For some background context, there are two start/stop generator types: + + - startstop0 + The original start/stop generator. This turns the Cerbo's built-in relay on/off. + On D-Bus, the uid is "com.victronenergy.generator.startstop0". + On MQTT, the service uid is "mqtt/generator/0". + + - startstop1 + This works with an actual genset, by sending a command to it instead of closing the relay. + That is, it controls any genset service with start-stop capabilities that can be remotely + commanded. For example, FischerPanda, CompAp and DSE controllers. + + On D-Bus, the uid is "com.victronenergy.generator.startstop1". + On MQTT, the service uid is found by locating the generator service with a /GensetService + value that matches that of a genset or dcgenset service. It might turn out to be + "mqtt/generator/1", but that is not guaranteed. + + So, unlike for many other service types, these services these do not refer to different generator + instances; instead, they are used to distinguish between two different types of generators. +*/ + +QtObject { + id: root + + property string gensetServiceUid + + // On D-Bus, the startstop1 generator is at com.victronenergy.generator.startstop1. + // On MQTT, the startstop1 generator is the one with GensetService=com.victronenergy.genset.* + // (or GensetService=com.victronenergy.dcgenset.* if this is a dcgenset) + readonly property string startStop1Uid: BackendConnection.type === BackendConnection.MqttSource + ? _generatorWithGensetService + : BackendConnection.uidPrefix() + "/com.victronenergy.generator.startstop1" + + property string _generatorWithGensetService + + readonly property Instantiator _generatorObjects: Instantiator { + model: BackendConnection.type === BackendConnection.MqttSource ? Global.generators.model : null + delegate: VeQuickItem { + uid: model.device.serviceUid + "/GensetService" + onValueChanged: { + const serviceType = BackendConnection.serviceTypeFromUid(root.gensetServiceUid) + if ( (isValid && serviceType === "dcgenset" && value.startsWith("com.victronenergy.dcgenset.")) + || (isValid && serviceType !== "dcgenset" && value.startsWith("com.victronenergy.genset.")) ) { + root._generatorWithGensetService = model.device.serviceUid + } + } + } + } +} diff --git a/components/PageGensetModel.qml b/components/PageGensetModel.qml index 5cfe56ed1..ad7f1b840 100644 --- a/components/PageGensetModel.qml +++ b/components/PageGensetModel.qml @@ -11,30 +11,8 @@ ObjectModel { property string bindPrefix property string settingsBindPrefix: Global.systemSettings.serviceUid + "/Settings/Generator1" - property string startStopBindPrefix: startStop1Uid + property string startStopBindPrefix: _startStop1Finder.startStop1Uid readonly property string serviceType: BackendConnection.serviceTypeFromUid(bindPrefix) - - // On D-Bus, the startstop1 generator is at com.victronenergy.generator.startstop1. - // On MQTT, the startstop1 generator is the one with GensetService=com.victronenergy.genset.* - // (or GensetService=com.victronenergy.dcgenset.* if this is a dcgenset) - readonly property string startStop1Uid: BackendConnection.type === BackendConnection.MqttSource - ? generatorWithGensetService - : BackendConnection.uidPrefix() + "/com.victronenergy.generator.startstop1" - property string generatorWithGensetService - - property Instantiator generatorObjects: Instantiator { - model: BackendConnection.type === BackendConnection.MqttSource ? Global.generators.model : null - delegate: VeQuickItem { - uid: model.device.serviceUid + "/GensetService" - onValueChanged: { - if ( (isValid && root.dcGenset && value.startsWith("com.victronenergy.dcgenset.")) - || (isValid && !root.dcGenset && value.startsWith("com.victronenergy.genset.")) ) { - root.generatorWithGensetService = model.device.serviceUid - } - } - } - } - readonly property bool dcGenset: serviceType === "dcgenset" readonly property int nrOfPhases: phases.isValid ? phases.value : dcGenset ? 0 @@ -47,6 +25,10 @@ ObjectModel { uid: root.startStopBindPrefix ? root.startStopBindPrefix + "/Enabled" : "" } + readonly property GensetStartStop1Finder _startStop1Finder: GensetStartStop1Finder { + gensetServiceUid: root.bindPrefix + } + PrimaryListLabel { preferredVisible: root.gensetEnabled.value === 0 //% "This genset controller requires a helper relay to be controlled but the helper relay is not configured. Please configure Relay 1 under Settings → Relay to \"Connected genset helper relay\"."