-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These were previously added as VeQuickItem came from Victron.Velib, which could not be imported in the wasm build. However, VeQuickItem is now in Victron.Veutil, so it can safely be used in all builds, and DataPoint.qml can now use it directly inside a Component instead of loading it from a separate file.
- Loading branch information
Showing
7 changed files
with
111 additions
and
232 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
** Copyright (C) 2022 Victron Energy B.V. | ||
*/ | ||
|
||
import QtQuick | ||
import Victron.VenusOS | ||
import Victron.Veutil | ||
|
||
QtObject { | ||
id: root | ||
|
||
// Valid 'source' values are: | ||
// - dbus paths, e.g. 'com.victronenergy.blah/path/to/value' | ||
// - as above, but with as full dbus uid, e.g. 'dbus/com.victronenergy.blah/path/to/value' | ||
// - full mqtt uid, e.g. 'mqtt/blah/device-id/path/to/value' | ||
// Note that dbus and mqtt uids should only be used when the application is using their | ||
// respective backend connection types. If a mqtt uid is used on a dbus connection, for | ||
// example, the DataPoint would not produce a valid value. | ||
property string source | ||
property var sourceObject | ||
|
||
readonly property var value: sourceObject ? sourceObject.value : undefined | ||
readonly property bool valid: value !== undefined | ||
|
||
property bool hasMin | ||
property bool hasMax | ||
readonly property var min: hasMin && sourceObject ? sourceObject.min : undefined | ||
readonly property var max: hasMax && sourceObject ? sourceObject.max : undefined | ||
property bool invalidate: true | ||
|
||
property Component _dbusComponent : Component { | ||
VeQuickItem { | ||
uid: root.source.startsWith("dbus/") ? root.source : "dbus/" + root.source | ||
invalidate: root.invalidate | ||
|
||
onInvalidateChanged: root.invalidate = invalidate | ||
} | ||
} | ||
|
||
property Component _mqttComponent : Component { | ||
VeQuickItem { | ||
readonly property string mqttUid: root.source.startsWith("mqtt/") ? root.source : _uidConverter.mqttUid | ||
|
||
readonly property SingleUidHelper _uidConverter: SingleUidHelper { | ||
dbusUid: root.source.length === 0 || root.source.startsWith("mqtt/") | ||
? "" | ||
: (root.source.startsWith("dbus/") ? root.source : "dbus/" + root.source) | ||
} | ||
|
||
uid: mqttUid | ||
|
||
onInvalidateChanged: root.invalidate = invalidate | ||
} | ||
} | ||
|
||
property Component _mockComponent : Component { | ||
QtObject { | ||
id: root | ||
|
||
property string source: root.source | ||
property var value: Global.mockDataSimulator ? Global.mockDataSimulator.mockDataValues[source] : undefined | ||
property real min: 0 | ||
property real max: 100 | ||
property bool invalidate: true | ||
|
||
function setValue(v) { | ||
value = v | ||
} | ||
|
||
onInvalidateChanged: root.invalidate = invalidate | ||
} | ||
} | ||
|
||
function setValue(v) { | ||
if (sourceObject) { | ||
sourceObject.setValue(v) | ||
} else { | ||
console.warn("Set value() failed, no sourceObject for source", source) | ||
} | ||
} | ||
|
||
function _reset() { | ||
if (source.length === 0) { | ||
return | ||
} | ||
if (sourceObject) { | ||
sourceObject.destroy() | ||
sourceObject = null | ||
} | ||
switch (BackendConnection.type) { | ||
case BackendConnection.DBusSource: | ||
sourceObject = _dbusComponent.createObject(root) | ||
break | ||
case BackendConnection.MqttSource: | ||
sourceObject = _mqttComponent.createObject(root) | ||
break | ||
case BackendConnection.MockSource: | ||
sourceObject = _mockComponent.createObject(root) | ||
break | ||
default: | ||
console.warn("Unknown DataPoint source type:", BackendConnection.type) | ||
break | ||
} | ||
} | ||
|
||
onSourceChanged: _reset() | ||
Component.onCompleted: _reset() | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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