From 12ff672216a77bf4ccc3e1e0dbd4c67fac55f9c1 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 27 Mar 2018 22:31:50 +0200 Subject: [PATCH] only init devices after their parents have been set up --- libnymea/devicemanager.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/libnymea/devicemanager.cpp b/libnymea/devicemanager.cpp index dcce8372..a4d9340c 100644 --- a/libnymea/devicemanager.cpp +++ b/libnymea/devicemanager.cpp @@ -1149,14 +1149,28 @@ void DeviceManager::loadConfiguredDevices() // We always add the device to the list in this case. If its in the storedDevices // it means that it was working at some point so lets still add it as there might - // be rules associated with this device. Device::setupCompleted() will be false. - DeviceSetupStatus status = setupDevice(device); + // be rules associated with this device. m_configuredDevices.insert(device->id(), device); + } + settings.endGroup(); + QHash setupList = m_configuredDevices; + while (!setupList.isEmpty()) { + Device *device = nullptr; + foreach (Device *d, setupList) { + if (d->parentId().isNull() || !setupList.contains(d->parentId())) { + device = d; + setupList.take(d->id()); + break; + } + } + Q_ASSERT(device != nullptr); + + DeviceSetupStatus status = setupDevice(device); if (status == DeviceSetupStatus::DeviceSetupStatusSuccess) postSetupDevice(device); } - settings.endGroup(); + } void DeviceManager::storeConfiguredDevices()