Skip to content

Commit

Permalink
Fix up VE.CAN device settings
Browse files Browse the repository at this point in the history
- fix device model for MQTT backends
- device instance number should be editable from the device list
- use common words
  • Loading branch information
blammit committed Aug 1, 2023
1 parent 125d251 commit 2701501
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 31 deletions.
18 changes: 6 additions & 12 deletions pages/settings/PageSettingsVecanDevice.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@ Page {
model: ObjectModel {

ListTextItem {
//% "Model name"
text: qsTrId("settings_vecan_model_name")
text: CommonWords.model_name
dataSource: root.bindPrefix + "/ModelName"
}

ListTextItem {
//% "Custom name"
text: qsTrId("settings_vecan_custom_name")
text: CommonWords.custom_name
dataSource: root.bindPrefix + "/CustomName"
}

Expand All @@ -37,8 +35,7 @@ Page {
}

ListTextItem {
//% "Manufacturer"
text: qsTrId("settings_vecan_manufacturer")
text: CommonWords.manufacturer
dataSource: root.bindPrefix + "/Manufacturer"
}

Expand All @@ -49,20 +46,17 @@ Page {
}

ListTextItem {
//% "Firmware Version"
text: qsTrId("settings_vecan_firmware_version")
text: CommonWords.firmware_version
dataSource: root.bindPrefix + "/FirmwareVersion"
}

ListTextItem {
//% "Serial Number"
text: qsTrId("settings_vecan_serial")
text: CommonWords.serial_number
dataSource: root.bindPrefix + "/Serial"
}

ListTextItem {
//% "Unique Identity Number"
text: qsTrId("settings_vecan_uid")
text: CommonWords.unique_identity_number
dataSource: root.bindPrefix + "/N2kUniqueNumber"
}
}
Expand Down
54 changes: 35 additions & 19 deletions pages/settings/PageSettingsVecanDevices.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import QtQuick
import QtQuick.Controls.impl as CP
import Victron.VenusOS
import Victron.Veutil
import "/components/Utils.js" as Utils
Expand All @@ -20,40 +21,55 @@ Page {
filterFlags: VeQItemSortTableModel.FilterOffline
dynamicSortFilter: true
model: VeQItemTableModel {
// TODO fix this 'uids' for MQTT, else will crash in MQTT mode
uids: ["dbus/com.victronenergy.vecan." + root.gateway + "/Devices"]
uids: BackendConnection.type === BackendConnection.DBusSource
? ["dbus/com.victronenergy.vecan." + root.gateway + "/Devices"]
: BackendConnection.type === BackendConnection.MqttSource
? ["mqtt/vecan/0/Devices"] // TODO this should change depending on the gateway!
: ""
flags: VeQItemTableModel.AddChildren | VeQItemTableModel.AddNonLeaves | VeQItemTableModel.DontAddItem
}
}

delegate: ListNavigationItem {
delegate: ListSpinBox {
id: listDelegate

text: "%1 [%2]".arg(customName.value || modelName.value).arg(uniqueNumber.value)
//% "Device# %1"
secondaryText: qsTrId("settings_vecan_device_number").arg(deviceInstance.value)
secondaryText: qsTrId("settings_vecan_device_number").arg(dataValue)
dataSource: model.uid + "/DeviceInstance"

DataPoint {
id: modelName
source: Utils.normalizedSource(model.uid) + "/ModelName"
CP.ColorImage {
parent: listDelegate.content
anchors.verticalCenter: parent.verticalCenter
source: "/images/icon_back_32.svg"
rotation: 180
color: listDelegate.containsPress ? Theme.color.listItem.down.forwardIcon : Theme.color.listItem.forwardIcon
}

DataPoint {
id: customName
source: Utils.normalizedSource(model.uid) + "/CustomName"
MouseArea {
id: mouseArea

parent: listDelegate.backgroundRect
anchors.fill: parent
onClicked: {
Global.pageManager.pushPage("/pages/settings/PageSettingsVecanDevice.qml",
{ bindPrefix: model.uid, title: text })
}
}

DataPoint {
id: uniqueNumber
source: Utils.normalizedSource(model.uid) + "/N2kUniqueNumber"
VeQuickItem {
id: modelName
uid: model.uid + "/ModelName"
}

DataPoint {
id: deviceInstance
source: model.uid + "/DeviceInstance"
VeQuickItem {
id: customName
uid: model.uid + "/CustomName"
}

onClicked: {
Global.pageManager.pushPage("/pages/settings/PageSettingsVecanDevice.qml",
{ bindPrefix: Utils.normalizedSource(model.uid), title: text })
VeQuickItem {
id: uniqueNumber
uid: model.uid + "/N2kUniqueNumber"
}
}
}
Expand Down

0 comments on commit 2701501

Please sign in to comment.