Merge PR #256: Complete support for reconfiguring devices
This commit is contained in:
commit
7ca34602af
@ -308,6 +308,7 @@ void DeviceManager::removeDeviceResponse(const QVariantMap ¶ms)
|
|||||||
|
|
||||||
void DeviceManager::pairDeviceResponse(const QVariantMap ¶ms)
|
void DeviceManager::pairDeviceResponse(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Pair device response:" << params;
|
||||||
emit pairDeviceReply(params.value("params").toMap());
|
emit pairDeviceReply(params.value("params").toMap());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,23 +370,40 @@ void DeviceManager::addDiscoveredDevice(const QUuid &deviceClassId, const QUuid
|
|||||||
m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse");
|
m_jsonClient->sendCommand("Devices.AddConfiguredDevice", params, this, "addDeviceResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name)
|
void DeviceManager::pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name)
|
||||||
{
|
{
|
||||||
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
|
qDebug() << "JsonRpc: pair discovered device " << deviceDescriptorId.toString();
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("name", name);
|
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
|
||||||
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
|
params.insert("deviceDescriptorId", deviceDescriptorId.toString());
|
||||||
|
params.insert("deviceParams", deviceParams);
|
||||||
|
params.insert("name", name);
|
||||||
|
|
||||||
|
if (!m_jsonClient->ensureServerVersion("3.2")) {
|
||||||
|
params.insert("deviceClassId", deviceClassId);
|
||||||
|
}
|
||||||
|
|
||||||
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeviceManager::pairDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams)
|
void DeviceManager::pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name)
|
||||||
{
|
{
|
||||||
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
|
qDebug() << "JsonRpc: pair device " << deviceClassId.toString();
|
||||||
QVariantMap params;
|
QVariantMap params;
|
||||||
params.insert("name", name);
|
|
||||||
params.insert("deviceClassId", deviceClassId.toString());
|
params.insert("deviceClassId", deviceClassId.toString());
|
||||||
params.insert("deviceParams", deviceParams);
|
params.insert("deviceParams", deviceParams);
|
||||||
|
params.insert("name", name);
|
||||||
|
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceManager::rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name)
|
||||||
|
{
|
||||||
|
qDebug() << "JsonRpc: pair device (reconfigure)" << deviceId;
|
||||||
|
QVariantMap params;
|
||||||
|
params.insert("deviceId", deviceId.toString());
|
||||||
|
params.insert("deviceParams", deviceParams);
|
||||||
|
if (!name.isEmpty()) {
|
||||||
|
params.insert("name", name);
|
||||||
|
}
|
||||||
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
m_jsonClient->sendCommand("Devices.PairDevice", params, this, "pairDeviceResponse");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -67,9 +67,12 @@ public:
|
|||||||
bool fetchingData() const;
|
bool fetchingData() const;
|
||||||
|
|
||||||
Q_INVOKABLE void addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE void addDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
||||||
|
// param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1
|
||||||
Q_INVOKABLE void addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams);
|
Q_INVOKABLE void addDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name, const QVariantList &deviceParams);
|
||||||
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QString &name);
|
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QVariantList &deviceParams, const QString &name);
|
||||||
Q_INVOKABLE void pairDevice(const QUuid &deviceClassId, const QString &name, const QVariantList &deviceParams);
|
// param deviceClassId is deprecated and should be removed when minimum JSONRPC version is 3.1
|
||||||
|
Q_INVOKABLE void pairDiscoveredDevice(const QUuid &deviceClassId, const QUuid &deviceDescriptorId, const QVariantList &deviceParams, const QString &name);
|
||||||
|
Q_INVOKABLE void rePairDevice(const QUuid &deviceId, const QVariantList &deviceParams, const QString &name = QString());
|
||||||
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString(), const QString &username = QString());
|
Q_INVOKABLE void confirmPairing(const QUuid &pairingTransactionId, const QString &secret = QString(), const QString &username = QString());
|
||||||
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
Q_INVOKABLE void removeDevice(const QUuid &deviceId, RemovePolicy policy = RemovePolicyNone);
|
||||||
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
Q_INVOKABLE void editDevice(const QUuid &deviceId, const QString &name);
|
||||||
|
|||||||
@ -18,7 +18,7 @@ Page {
|
|||||||
signal done();
|
signal done();
|
||||||
|
|
||||||
header: NymeaHeader {
|
header: NymeaHeader {
|
||||||
text: qsTr("Set up thing")
|
text: root.device ? qsTr("Reconfigure %1").arg(root.device.name) : qsTr("Set up %1").arg(root.deviceClass.displayName)
|
||||||
onBackPressed: {
|
onBackPressed: {
|
||||||
if (internalPageStack.depth > 1) {
|
if (internalPageStack.depth > 1) {
|
||||||
internalPageStack.pop();
|
internalPageStack.pop();
|
||||||
@ -45,15 +45,54 @@ Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
print("Starting setup wizard")
|
||||||
if (root.deviceClass.createMethods.indexOf("CreateMethodDiscovery") !== -1) {
|
if (root.deviceClass.createMethods.indexOf("CreateMethodDiscovery") !== -1) {
|
||||||
|
print("CreateMethodDiscovery")
|
||||||
if (deviceClass["discoveryParamTypes"].count > 0) {
|
if (deviceClass["discoveryParamTypes"].count > 0) {
|
||||||
|
print("Discovery params:", deviceClass.discoveryParamTypes.count)
|
||||||
internalPageStack.push(discoveryParamsPage)
|
internalPageStack.push(discoveryParamsPage)
|
||||||
} else {
|
} else {
|
||||||
|
print("Starting discovery...")
|
||||||
discovery.discoverDevices(deviceClass.id)
|
discovery.discoverDevices(deviceClass.id)
|
||||||
internalPageStack.push(discoveryPage, {deviceClass: deviceClass})
|
internalPageStack.push(discoveryPage, {deviceClass: deviceClass})
|
||||||
}
|
}
|
||||||
} else if (deviceClass.createMethods.indexOf("CreateMethodUser") !== -1) {
|
} else if (root.deviceClass.createMethods.indexOf("CreateMethodUser") !== -1) {
|
||||||
internalPageStack.push(paramsPage)
|
print("CreateMethodUser")
|
||||||
|
// Setting up a new device
|
||||||
|
if (!root.device) {
|
||||||
|
print("New device. Opening params page")
|
||||||
|
internalPageStack.push(paramsPage)
|
||||||
|
|
||||||
|
// Reconfigure
|
||||||
|
} else if (root.device) {
|
||||||
|
print("Existing device")
|
||||||
|
// There are params. Open params page in any case
|
||||||
|
if (root.deviceClass.paramTypes.count > 0) {
|
||||||
|
print("Params:", root.deviceClass.paramTypes.count)
|
||||||
|
internalPageStack.push(paramsPage)
|
||||||
|
|
||||||
|
// No params... go straight to reconfigure/repair
|
||||||
|
} else {
|
||||||
|
print("no params")
|
||||||
|
switch (root.deviceClass.setupMethod) {
|
||||||
|
case 0:
|
||||||
|
print("reconfiguring...")
|
||||||
|
// This totally does not make sense... Maybe we should hide the reconfigure button if there are no params?
|
||||||
|
engine.deviceManager.reconfigureDevice(root.device.id, [])
|
||||||
|
busyOverlay.shown = true;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
print("re-pairing", root.device.id)
|
||||||
|
engine.deviceManager.rePairDevice(root.device.id, []);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
console.warn("Unahndled setup method!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +220,7 @@ Page {
|
|||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
anchors.bottomMargin: app.margins
|
||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@ -202,28 +242,6 @@ Page {
|
|||||||
onClicked: {
|
onClicked: {
|
||||||
d.deviceDescriptor = discoveryProxy.get(index);
|
d.deviceDescriptor = discoveryProxy.get(index);
|
||||||
d.deviceName = model.name;
|
d.deviceName = model.name;
|
||||||
|
|
||||||
// Overriding params for reconfiguring discovered devices not supported by core yet
|
|
||||||
// So if we are reconfiguring and discovering, go straight to end
|
|
||||||
|
|
||||||
if (root.device && d.deviceDescriptor) {
|
|
||||||
busyOverlay.shown = true;
|
|
||||||
|
|
||||||
switch (root.deviceClass.setupMethod) {
|
|
||||||
case 0:
|
|
||||||
engine.deviceManager.reconfigureDiscoveredDevice(root.device.id, d.deviceDescriptor.id);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, root.device.name);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
internalPageStack.push(paramsPage)
|
internalPageStack.push(paramsPage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -240,7 +258,7 @@ Page {
|
|||||||
Button {
|
Button {
|
||||||
id: manualAddButton
|
id: manualAddButton
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins; Layout.bottomMargin: app.margins
|
Layout.leftMargin: app.margins; Layout.rightMargin: app.margins;
|
||||||
visible: root.deviceClass.createMethods.indexOf("CreateMethodUser") >= 0
|
visible: root.deviceClass.createMethods.indexOf("CreateMethodUser") >= 0
|
||||||
text: qsTr("Add thing manually")
|
text: qsTr("Add thing manually")
|
||||||
onClicked: internalPageStack.push(paramsPage)
|
onClicked: internalPageStack.push(paramsPage)
|
||||||
@ -304,7 +322,7 @@ Page {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
visible: root.device === null
|
// visible: root.device === null
|
||||||
Label {
|
Label {
|
||||||
Layout.leftMargin: app.margins
|
Layout.leftMargin: app.margins
|
||||||
Layout.rightMargin: app.margins
|
Layout.rightMargin: app.margins
|
||||||
@ -378,18 +396,17 @@ Page {
|
|||||||
case 4:
|
case 4:
|
||||||
case 5:
|
case 5:
|
||||||
if (root.device) {
|
if (root.device) {
|
||||||
// if (d.deviceDescriptor) {
|
if (d.deviceDescriptor) {
|
||||||
// engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text);
|
engine.deviceManager.pairDiscoveredDevice(root.deviceClass.id, d.deviceDescriptor.id, params, nameTextField.text);
|
||||||
// } else {
|
} else {
|
||||||
// engine.deviceManager.pairDevice(root.deviceClass.id, nameTextField.text, params);
|
engine.deviceManager.rePairDevice(root.device.id, params, nameTextField.text);
|
||||||
// }
|
}
|
||||||
console.warn("Unhandled setupMethod!")
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (d.deviceDescriptor) {
|
if (d.deviceDescriptor) {
|
||||||
engine.deviceManager.pairDevice(root.deviceClass.id, d.deviceDescriptor.id, nameTextField.text);
|
engine.deviceManager.pairDevice(d.deviceDescriptor.id, params, nameTextField.text);
|
||||||
} else {
|
} else {
|
||||||
engine.deviceManager.pairDevice(root.deviceClass.id, nameTextField.text, params);
|
engine.deviceManager.pairDevice(root.deviceClass.id, params, nameTextField.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user