-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global.solarDevices.model contains all solarcharger devices, as well as any multi and inverter devices with /NrOfTrackers > 0. Add a mock inverter that has a tracker. This prepares for the removal of Global.solarChargers. Part of #1574
- Loading branch information
Showing
7 changed files
with
225 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
** Copyright (C) 2025 Victron Energy B.V. | ||
** See LICENSE.txt for license information. | ||
*/ | ||
|
||
import QtQuick | ||
import Victron.VenusOS | ||
|
||
DeviceModel { | ||
id: root | ||
|
||
modelId: "solarDevices" | ||
|
||
readonly property Instantiator _serviceObjects: Instantiator { | ||
model: ["solarcharger", "multi", "inverter"] | ||
delegate: Instantiator { | ||
id: serviceInstantiator | ||
|
||
required property string modelData | ||
readonly property ServiceModelLoader modelLoader: ServiceModelLoader { | ||
serviceType: modelData | ||
} | ||
|
||
model: modelLoader.item | ||
delegate: SolarDevice { | ||
id: solarDevice | ||
|
||
// solarcharger devices are always included in the model. | ||
// For multi and inverter devices, only include them if /NrOfTrackers > 0. | ||
readonly property bool hasSolarData: valid | ||
&& (serviceInstantiator.modelData === "solarcharger" | ||
|| (_nrOfTrackers.isValid && _nrOfTrackers.value > 0)) | ||
|
||
serviceUid: model.uid | ||
|
||
onHasSolarDataChanged: { | ||
if (hasSolarData) { | ||
root.addDevice(solarDevice) | ||
} else { | ||
root.removeDevice(solarDevice.serviceUid) | ||
} | ||
} | ||
|
||
readonly property VeQuickItem _nrOfTrackers: VeQuickItem { | ||
uid: solarDevice.serviceUid + "/NrOfTrackers" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
** Copyright (C) 2025 Victron Energy B.V. | ||
** See LICENSE.txt for license information. | ||
*/ | ||
|
||
import QtQuick | ||
import Victron.VenusOS | ||
|
||
QtObject { | ||
id: root | ||
|
||
property SolarDeviceModel model: SolarDeviceModel { } | ||
|
||
function formatTrackerName(trackerName, trackerIndex, totalTrackerCount, deviceName, format) { | ||
if (format === VenusOS.TrackerName_WithDevicePrefix) { | ||
if (trackerName.length > 0) { | ||
return "%1-%2".arg(deviceName).arg(trackerName) | ||
} else if (totalTrackerCount > 1) { | ||
return "%1-#%2".arg(deviceName).arg(trackerIndex + 1) | ||
} else { | ||
return deviceName | ||
} | ||
} else { // format === VenusOS.TrackerName_NoDevicePrefix | ||
if (trackerName.length > 0) { | ||
return trackerName | ||
} else { | ||
return "#%1".arg(trackerIndex + 1) | ||
} | ||
} | ||
} | ||
|
||
Component.onCompleted: Global.solarDevices = root | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
** Copyright (C) 2025 Victron Energy B.V. | ||
** See LICENSE.txt for license information. | ||
*/ | ||
|
||
import QtQuick | ||
import Victron.VenusOS | ||
|
||
// SolarDevice is a base type for devices with PV trackers and history data. | ||
// This includes the devices provided by solarcharger services, as well as multi and inverter | ||
// services where /NrOfTrackers > 0. | ||
|
||
Device { | ||
id: root | ||
|
||
readonly property ListModel trackers: ListModel {} | ||
readonly property real power: _totalPower.isValid ? _totalPower.value : NaN | ||
readonly property alias history: _history | ||
|
||
// This is the overall error history. | ||
// For the per-day error history, use dailyHistory(day).errorModel | ||
readonly property alias errorModel: _history.errorModel | ||
|
||
signal yieldUpdatedForDay(day: int, yieldKwh: real) | ||
|
||
function dailyHistory(day) { | ||
return _history.dailyHistory(day) | ||
} | ||
|
||
function dailyTrackerHistory(day, trackerIndex) { | ||
return _history.dailyTrackerHistory(day, trackerIndex) | ||
} | ||
|
||
function trackerName(trackerIndex, format) { | ||
const tracker = _trackerObjects.objectAt(trackerIndex) | ||
const trackerName = tracker ? tracker.name || "" : "" | ||
return Global.solarChargers.formatTrackerName(trackerName, trackerIndex, trackers.count, root.name, format) | ||
} | ||
|
||
//--- internal members below --- | ||
|
||
readonly property VeQuickItem _totalPower: VeQuickItem { | ||
uid: root.serviceUid + "/Yield/Power" | ||
} | ||
|
||
//--- history --- | ||
|
||
readonly property SolarHistory _history: SolarHistory { | ||
id: _history | ||
bindPrefix: root.serviceUid | ||
deviceName: root.name | ||
trackerCount: root.trackers.count | ||
} | ||
|
||
//--- Solar trackers --- | ||
|
||
readonly property VeQuickItem _trackerCount: VeQuickItem { | ||
uid: root.serviceUid + "/NrOfTrackers" | ||
} | ||
|
||
readonly property Instantiator _trackerObjects: Instantiator { | ||
model: _trackerCount.value || 1 // there is always at least one tracker, even if NrOfTrackers is not set | ||
delegate: QtObject { | ||
id: tracker | ||
|
||
readonly property int modelIndex: model.index | ||
readonly property real power: root.trackers.count <= 1 ? root.power : _power.value || 0 | ||
readonly property real voltage: _voltage.value || 0 | ||
readonly property real current: isNaN(power) || isNaN(voltage) || voltage === 0 ? NaN : power / voltage | ||
readonly property string name: _name.value || "" | ||
|
||
readonly property VeQuickItem _voltage: VeQuickItem { | ||
uid: root.trackers.count <= 1 | ||
? root.serviceUid + "/Pv/V" | ||
: root.serviceUid + "/Pv/" + model.index + "/V" | ||
} | ||
|
||
readonly property VeQuickItem _power: VeQuickItem { | ||
uid: root.trackers.count === 1 | ||
? "" // only 1 tracker, use root.power instead (i.e. same as /Yield/Power) | ||
: root.serviceUid + "/Pv/" + model.index + "/P" | ||
} | ||
|
||
readonly property VeQuickItem _name: VeQuickItem { | ||
uid: root.serviceUid + "/Pv/" + model.index + "/Name" | ||
} | ||
} | ||
|
||
onObjectAdded: function(index, object) { | ||
let insertionIndex = root.trackers.count | ||
for (let i = 0; i < root.trackers.count; ++i) { | ||
const sortIndex = root.trackers.get(i).solarTracker.modelIndex | ||
if (index < sortIndex) { | ||
insertionIndex = i | ||
break | ||
} | ||
} | ||
root.trackers.insert(insertionIndex, {"solarTracker": object}) | ||
} | ||
|
||
onObjectRemoved: function(index, object) { | ||
for (let i = 0; i < root.trackers.count; ++i) { | ||
if (root.trackers.get(i).solarTracker.serviceUid === object.serviceUid) { | ||
root.trackers.remove(i) | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters