From 4275f9052f2f1b62c7ca90247a7c43d6f9e80339 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 22 Mar 2019 16:19:41 +0100 Subject: [PATCH] Fix TimeDescriptors getting lost when updating a rule by removing a device --- libnymea-core/nymeacore.cpp | 10 ++++++---- libnymea-core/ruleengine.cpp | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index 104b5290..5439935c 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -251,12 +251,13 @@ void NymeaCore::destroy() /*! Removes a configured \l{Device} with the given \a deviceId and \a removePolicyList. */ QPair > NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const QHash &removePolicyList) { - // Check if this is a child device Device *device = m_deviceManager->findConfiguredDevice(deviceId); - if (!device) + if (!device) { return QPair > (DeviceManager::DeviceErrorDeviceNotFound, QList()); + } + // Check if this is a child device if (!device->parentId().isNull()) { qCWarning(dcDeviceManager) << "The device is a child of" << device->parentId().toString() << ". Please remove the parent device."; return QPair > (DeviceManager::DeviceErrorDeviceIsChild, QList()); @@ -347,12 +348,13 @@ QPair > NymeaCore::removeConfiguredDev /*! Removes a configured \l{Device} with the given \a deviceId and \a removePolicy. */ DeviceManager::DeviceError NymeaCore::removeConfiguredDevice(const DeviceId &deviceId, const RuleEngine::RemovePolicy &removePolicy) { - // Check if this is a child device Device *device = m_deviceManager->findConfiguredDevice(deviceId); - if (!device) + if (!device) { return DeviceManager::DeviceErrorDeviceNotFound; + } + // Check if this is a child device if (!device->parentId().isNull()) { qCWarning(dcDeviceManager) << "The device is a child of" << device->parentId().toString() << ". Please remove the parent device."; return DeviceManager::DeviceErrorDeviceIsChild; diff --git a/libnymea-core/ruleengine.cpp b/libnymea-core/ruleengine.cpp index 3edbbe28..2ebca7f6 100644 --- a/libnymea-core/ruleengine.cpp +++ b/libnymea-core/ruleengine.cpp @@ -903,6 +903,7 @@ void RuleEngine::removeDeviceFromRule(const RuleId &id, const DeviceId &deviceId newRule.setName(rule.name()); newRule.setEventDescriptors(eventDescriptors); newRule.setStateEvaluator(stateEvalatuator); + newRule.setTimeDescriptor(rule.timeDescriptor()); newRule.setActions(actions); newRule.setExitActions(exitActions); m_rules[id] = newRule;