From 65bd08b547f6a498189ba6922d675d74f1db59f2 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Sun, 29 Mar 2020 17:56:09 +0200 Subject: [PATCH] FlowerCare: Fix rediscovery --- flowercare/integrationpluginflowercare.cpp | 30 +++++++--------------- flowercare/integrationpluginflowercare.h | 2 -- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/flowercare/integrationpluginflowercare.cpp b/flowercare/integrationpluginflowercare.cpp index 27d5c289..61d6429d 100644 --- a/flowercare/integrationpluginflowercare.cpp +++ b/flowercare/integrationpluginflowercare.cpp @@ -82,19 +82,17 @@ void IntegrationPluginFlowercare::discoverThings(ThingDiscoveryInfo *info) foreach (const QBluetoothDeviceInfo &deviceInfo, reply->discoveredDevices()) { qCDebug(dcFlowerCare()) << "Discovered device" << deviceInfo.name(); if (deviceInfo.name().contains("Flower care")) { - if (!verifyExistingDevices(deviceInfo)) { - ThingDescriptor descriptor(flowerCareThingClassId, deviceInfo.name(), deviceInfo.address().toString()); - ParamList params; - params << Param(flowerCareThingMacParamTypeId, deviceInfo.address().toString()); - descriptor.setParams(params); - foreach (Thing *existingThing, myThings()) { - if (existingThing->paramValue(flowerCareThingMacParamTypeId).toString() == deviceInfo.address().toString()) { - descriptor.setThingId(existingThing->id()); - break; - } + ThingDescriptor descriptor(flowerCareThingClassId, deviceInfo.name(), deviceInfo.address().toString()); + ParamList params; + params << Param(flowerCareThingMacParamTypeId, deviceInfo.address().toString()); + descriptor.setParams(params); + foreach (Thing *existingThing, myThings()) { + if (existingThing->paramValue(flowerCareThingMacParamTypeId).toString() == deviceInfo.address().toString()) { + descriptor.setThingId(existingThing->id()); + break; } - info->addThingDescriptor(descriptor); } + info->addThingDescriptor(descriptor); } } @@ -158,16 +156,6 @@ void IntegrationPluginFlowercare::thingRemoved(Thing *thing) } } -bool IntegrationPluginFlowercare::verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo) -{ - foreach (Thing *thing, m_list.keys()) { - if (thing->paramValue(flowerCareThingMacParamTypeId).toString() == deviceInfo.address().toString()) - return true; - } - - return false; -} - void IntegrationPluginFlowercare::onPluginTimer() { diff --git a/flowercare/integrationpluginflowercare.h b/flowercare/integrationpluginflowercare.h index 0cf96d86..96184d83 100644 --- a/flowercare/integrationpluginflowercare.h +++ b/flowercare/integrationpluginflowercare.h @@ -61,8 +61,6 @@ private: QHash m_list; QHash m_refreshMinutes; - bool verifyExistingDevices(const QBluetoothDeviceInfo &deviceInfo); - private slots: void onPluginTimer(); void onSensorDataReceived(quint8 batteryLevel, double degreeCelsius, double lux, double moisture, double fertility);