Skip to content

Commit

Permalink
Move startstop1 uid finding feature into a separate component
Browse files Browse the repository at this point in the history
This is a general cleanup to make it clear how to reuse this
functionality from elsewhere if that is needed.
  • Loading branch information
blammit committed Jan 15, 2025
1 parent e4b8b6c commit 6cc20dd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 23 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions components/GensetStartStop1Finder.qml
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}
28 changes: 5 additions & 23 deletions components/PageGensetModel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +25,10 @@ ObjectModel {
uid: root.startStopBindPrefix ? root.startStopBindPrefix + "/Enabled" : ""
}

readonly property GensetStartStop1Finder _startStop1Finder: GensetStartStop1Finder {
gensetServiceUid: root.bindPrefix
}

PrimaryListLabel {
allowed: 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\"."
Expand Down

0 comments on commit 6cc20dd

Please sign in to comment.