From 14bc0eb73e84eeb78cea604e916c216af16af772 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 10 Oct 2019 13:07:22 +0200 Subject: [PATCH] fix pairing for oauth --- .../devices/devicemanagerimplementation.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/libnymea-core/devices/devicemanagerimplementation.cpp b/libnymea-core/devices/devicemanagerimplementation.cpp index edf4020c..22a9da0b 100644 --- a/libnymea-core/devices/devicemanagerimplementation.cpp +++ b/libnymea-core/devices/devicemanagerimplementation.cpp @@ -495,7 +495,9 @@ Device::DeviceError DeviceManagerImplementation::setDeviceSettings(const DeviceI DevicePairingInfo* DeviceManagerImplementation::pairDevice(const DeviceClassId &deviceClassId, const QString &name, const ParamList ¶ms) { PairingTransactionId transactionId = PairingTransactionId::createPairingTransactionId(); - DevicePairingInfo *info = new DevicePairingInfo(transactionId, deviceClassId, DeviceId(), name, params, DeviceId(), this, 30000); + // Create new device id + DeviceId newDeviceId = DeviceId::createDeviceId(); + DevicePairingInfo *info = new DevicePairingInfo(transactionId, deviceClassId, newDeviceId, name, params, DeviceId(), this, 30000); pairDeviceInternal(info); return info; } @@ -521,7 +523,12 @@ DevicePairingInfo* DeviceManagerImplementation::pairDevice(const DeviceClassId & return info; } - DevicePairingInfo *info = new DevicePairingInfo(pairingTransactionId, deviceClassId, deviceDescriptor.deviceId(), name, deviceDescriptor.params(), deviceDescriptor.parentDeviceId(), this, 30000); + DeviceId deviceId = deviceDescriptor.deviceId(); + // If it's a new device (not a reconfiguration), create a new DeviceId now. + if (deviceId.isNull()) { + deviceId = DeviceId::createDeviceId(); + } + DevicePairingInfo *info = new DevicePairingInfo(pairingTransactionId, deviceClassId, deviceId, name, deviceDescriptor.params(), deviceDescriptor.parentDeviceId(), this, 30000); pairDeviceInternal(info); return info; } @@ -548,13 +555,9 @@ DevicePairingInfo *DeviceManagerImplementation::confirmPairing(const PairingTran return info; } - // If we already have a deviceId, we're reconfiguring an existing device, else we're adding a new one. - bool addNewDevice = false; DeviceId deviceId = context.deviceId; - if (deviceId.isNull()) { - deviceId = DeviceId::createDeviceId(); - addNewDevice = true; - } + // If we already have a device for this ID, we're reconfiguring an existing device, else we're adding a new one. + bool addNewDevice = !m_configuredDevices.contains(context.deviceId); // We're using two different info objects here, one to hand over to the plugin for the pairing, the other we give out // to the user. After the internal one has finished, we'll start a setupDevice job and finish the external pairingInfo only after