Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmake/ModuleMock_Sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(VictronMock_QML_MODULE_SOURCES
data/mock/MotorDrivesImpl.qml
data/mock/MockNotification.qml
data/mock/NotificationsImpl.qml
data/mock/OpportunityLoadsImpl.qml
data/mock/SolarInputsImpl.qml
data/mock/SystemAcImpl.qml
data/mock/SystemDcImpl.qml
Expand Down
5 changes: 5 additions & 0 deletions cmake/ModuleVenus_Sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ set (VictronVenusOS_QML_MODULE_SOURCES
pages/settings/NetworkSettingsPageModel.qml
pages/settings/PageCanbusStatus.qml
pages/settings/PageChargeCurrentLimits.qml
pages/settings/PageControllableLoads.qml
pages/settings/PageControllableLoadsAcLoad.qml
pages/settings/PageControllableLoadsBattery.qml
pages/settings/PageControllableLoadsEVCS.qml
pages/settings/PageDeviceInfo.qml
pages/settings/PageGenerator.qml
pages/settings/PageGeneratorAcLoad.qml
Expand Down Expand Up @@ -692,6 +696,7 @@ set(VictronVenusOS_RESOURCES
images/alternator.svg
images/breadcrumb_lhs.svg
images/breadcrumb_rhs.svg
images/icon_arrow.svg
images/icon_battery_24.svg
images/icon_battery_charging_24.svg
images/icon_battery_discharging_24.svg
Expand Down
1 change: 1 addition & 0 deletions data/mock/MockSetup.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Item {
MiscServicesImpl {}
MotorDrivesImpl {}
NotificationsImpl {}
OpportunityLoadsImpl {}
SolarInputsImpl {}
SystemAcImpl {}
SystemDcImpl {}
Expand Down
71 changes: 71 additions & 0 deletions data/mock/OpportunityLoadsImpl.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

/*
** Copyright (C) 2026 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

Item {
id: root

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a new JSON file for an opportunityloads service to data/mock/conf/services/ and add the file to data/mock/conf/maximal.json? Then we can easily choose whether to load the service for different configurations.

property var jsonArray: [
{
"controllable": true,
"deviceInstance": 0,
"label": "Battery",
"serviceType": "battery",
"uniqueIdentifier": "battery"
},
{
"controllable": true,
"deviceInstance": 56,
"serviceType": "acload",
"uniqueIdentifier": "shellyPro2PMPVHeat2_56"
},
{
"controllable": true,
"deviceInstance": 54,
"serviceType": "acload",
"uniqueIdentifier": "shellyPro2PMPVHeat1_54"
},
{
"controllable": true,
"deviceInstance": 55,
"serviceType": "acload",
"uniqueIdentifier": "shellyPro2PMPVHeat2_55"
},
{
"serviceType":"evcharger",
"deviceInstance":920,
"uniqueIdentifier":"EVCS_Mock_3_Phase_920",
"controllable":true
}
]

VeQuickItem {
uid: BackendConnection.serviceUidForType("opportunityloads") + "/AvailableServices"
Component.onCompleted: setValue(JSON.stringify(jsonArray))
}

VeQuickItem {
uid: Global.systemSettings.serviceUid + "/Settings/OpportunityLoads/Mode"
Component.onCompleted: setValue(1)
}

VeQuickItem {
uid: BackendConnection.serviceUidForType("opportunityloads") + "/ReservationBasePower"
Component.onCompleted: setValue(4000)
}

VeQuickItem {
uid: BackendConnection.serviceUidForType("opportunityloads") + "/ReservationDecrement"
Component.onCompleted: setValue(40)
}

VeQuickItem {
uid: BackendConnection.serviceUidForType("opportunityloads") + "/BatteryLifeSupport"
Component.onCompleted: setValue(true)
}
}
3 changes: 3 additions & 0 deletions images/icon_arrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
203 changes: 203 additions & 0 deletions pages/settings/PageControllableLoads.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
** Copyright (C) 2026 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

Page {
id: root

property alias model: opportunityLoadsModel
property VeQuickItem loads: VeQuickItem {
uid: BackendConnection.serviceUidForType("opportunityloads") + "/AvailableServices"
invalidate: true
onValueChanged: {
const jsv = JSON.parse(value)
for (var i = 0; jsv && i < jsv.length; ++i) {
const newValue = jsv[i]
if ((opportunityLoadsModel.count < (i + 1)) || (newValue !== opportunityLoadsModel.get(i)))
opportunityLoadsModel.set(i, jsv[i])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: indent and add braces around this block

}
}
}

component Arrow: ListItemButton {
icon.source: "qrc:/images/icon_arrow.svg"
flat: false
height: parent.height - 2 * Theme.geometry_opportunityLoad_margin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The button in the design is like this:

Image

but the one here is much wider:

Image

}

component DevicePriorityListNavigation: ListNavigation {
id: devicePriorityDelegate

property string serviceType: ""
property int deviceInstance: -1
property string label: ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "" initialisers are not needed.

Also, label is not shown anywhere in the delegate - is it still needed?

property string uniqueIdentifier: ""
readonly property var devices: serviceType === "acload" ? acLoadDevices : serviceType === "evcharger" ? evcsDevices : null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use property type FilteredDeviceModel instead of var?

readonly property Device device: devices && deviceInstance > 0 ? devices.deviceForDeviceInstance(deviceInstance) : null
readonly property string pageSource: {
switch (serviceType) {
case "battery":
return "/pages/settings/PageControllableLoadsBattery.qml"
case "acload":
return "/pages/settings/PageControllableLoadsAcLoad.qml"
case "evcharger":
return "/pages/settings/PageControllableLoadsEVCS.qml"
default:
console.warn("Controllable Loads: Invalid service type.")
return ""
}
}

property alias text: primary.text
property var pageProperties: ({
"title": devicePriorityDelegate.text,
"device": devicePriorityDelegate.device
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageProperties seems unnecessary as a property as it never changes.


onClicked: Global.pageManager.pushPage(devicePriorityDelegate.pageSource, devicePriorityDelegate.pageProperties)
interactive: serviceType !== "evcharger" // TODO: remove this once backend supports "evcs maximum charging power limit".

Arrow {
id: upArrow

anchors {
left: parent.left
leftMargin: Theme.geometry_opportunityLoad_margin
verticalCenter: parent.verticalCenter
}
enabled: index !== 0
onClicked: {
root.model.move(index, index - 1, 1)
opportunityLoadsModel.writeToBackEnd()
}
}

Arrow {
id: downArrow

anchors {
left: upArrow.right
leftMargin: Theme.geometry_opportunityLoad_margin
verticalCenter: parent.verticalCenter
}
enabled: index !== (listView.count - 1)
rotation: 180
onClicked: {
root.model.move(index + 1, index, 1)
opportunityLoadsModel.writeToBackEnd()
}
}

Column {
anchors {
left: downArrow.right
leftMargin: Theme.geometry_listItem_content_horizontalMargin
verticalCenter: parent.verticalCenter
}

Label {
id: primary

property var device: devicePriorityDelegate.device

// eg. "Shelly switch (shellyPro2)"
readonly property string longName: ((device?.productName ?? "") && (device?.name ?? ""))
? (device.productName + " (" + device.name + ")")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really supposed to show both the product name and device name? Normally the device name is (customName || productName) so that the custom name is shown instead of the product name.

If it is supposed to show both, then this should check that the product name is not the same as the device name (i.e. when there is no custom name), otherwise the text would be duplicated.

Also, use translations here for the parentheses, e.g:

//: %1 = device product name, %2 = device name
//% "%1 (%2)"
longName: qsTrId("foo").arg(device?.productName ?? "").arg(device?.name ?? "")

: ""

font.pixelSize: Theme.font_size_body2
wrapMode: Text.Wrap
text: serviceType === "battery"
? "Battery"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Battery" needs translation. Also, it looks like this expression can be simplified to:

text: serviceType === "battery" ? CommonWords.battery : longName || device?.name || uniqueIdentifier || ""

: longName
? longName
: (device?.name ?? "")
? device.name
: uniqueIdentifier || ""
}
}
}

GradientListView {
model: VisibleItemModel {
ListSwitch {
dataItem.uid: BackendConnection.serviceUidForType("platform") + "/OpportunityLoads/Mode"
text: CommonWords.enabled
}

SettingsListHeader {
//% "Devices and Priorities"
text: qsTrId("pagecontrollableloads_devices_and_priorities")
}

SettingsColumn {
width: parent ? parent.width : 0
preferredVisible: opportunityLoadsModel.count > 0

ListView {
id: listView

model: opportunityLoadsModel
spacing: Theme.geometry_gradientList_spacing
implicitHeight: contentHeight
width: parent ? parent.width : 0
delegate: DevicePriorityListNavigation {
serviceType: model.serviceType
deviceInstance: model.deviceInstance
uniqueIdentifier: model.uniqueIdentifier
label: model.label
}
move: Transition {
NumberAnimation {
properties: "x,y"
easing.type: Easing.InOutQuad
}
}
displaced: Transition {
NumberAnimation {
properties: "x,y"
easing.type: Easing.InOutQuad
}
}
}
}

SettingsListHeader {
//% "Arrange the controllable devices according to their priority; the control algorithm will control them based on the currently available PV excess."
text: qsTrId("pagecontrollableloads_arrange")
font.pixelSize: Theme.font_size_tiny
width: 528
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded width? Also should the font size is too small, maybe font_size_caption instead?

wrapMode: Text.Wrap
}
}
}

ListModel {
id: opportunityLoadsModel

function writeToBackEnd() {
var newValue = []
for (var i = 0; i < opportunityLoadsModel.count; ++i) {
newValue.push(opportunityLoadsModel.get(i))
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary newline; also, use let instead of var.

loads.setValue(JSON.stringify(newValue))
}
}

FilteredDeviceModel {
id: acLoadDevices
objectName: "PageControllableLoads.acLoadDevices"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the objectNames from leftover debug?

serviceTypes: ["acload"]
}

FilteredDeviceModel {
id: evcsDevices
objectName: "PageControllableLoads.evcsDevices"
serviceTypes: ["evcharger"]
}
}
37 changes: 37 additions & 0 deletions pages/settings/PageControllableLoadsAcLoad.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

/*
** Copyright (C) 2026 Victron Energy B.V.
** See LICENSE.txt for license information.
*/

import QtQuick
import Victron.VenusOS

Page {
id: root

required property Device device

GradientListView {
model: VisibleItemModel {
ListQuantityField {
unit: VenusOS.Units_Watt
//% "Expected power consumption"
text: qsTrId("pagecontrollableloads_expected_power_consumption")
dataItem.uid: device.serviceUid + "/S2/0/RmSettings/PowerSetting"
}
ListQuantityField {
unit: VenusOS.Units_Time_Second
//% "Minimum run duration when turned on"
text: qsTrId("pagecontrollableloads_minimum_run_duration")
dataItem.uid: device.serviceUid + "/S2/0/RmSettings/OffHysteresis"
}
ListQuantityField {
unit: VenusOS.Units_Time_Second
//% "Minimum rest duration when turned off"
text: qsTrId("pagecontrollableloads_minimum_rest_duration")
dataItem.uid: device.serviceUid + "/S2/0/RmSettings/OnHysteresis"
}
}
}
}
Loading