This repository has been archived on 2026-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
powersync-app/nymea-app/ui/utils/ActionQueue.qml
2021-09-08 14:22:12 +02:00

52 lines
1.4 KiB
QML

import QtQuick 2.9
import Nymea 1.0
Item {
id: root
property Thing thing: null
// either or
property string stateName: ""
property StateType stateType: null
readonly property var pendingValue: d.queuedValue || d.pendingValue
function sendValue(value) {
if (d.pendingCommand != -1) {
// busy, cache value
d.queuedValue = value;
return;
}
d.pendingValue = value;
var stateName = root.stateType == null ? root.stateName : root.stateType.name
d.pendingCommand = root.thing.executeAction(stateName,
[{
paramName: stateName,
value: value
}])
d.queuedValue = null
}
QtObject {
id: d
property int pendingCommand: -1
property var pendingValue: null
property var queuedValue: null
}
Connections {
target: root.thing
onExecuteActionReply: {
if (d.pendingCommand == commandId) {
d.pendingCommand = -1;
if (d.queuedValue != null) {
root.sendValue(d.queuedValue)
} else {
d.pendingValue = null
}
}
}
}
}