From 4c1b0b56c93391bfa2b6992e197a0f19a531316a Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 2 Apr 2020 16:37:26 +0200 Subject: [PATCH] Shelly: Provide defaults for all params --- shelly/integrationpluginshelly.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/shelly/integrationpluginshelly.cpp b/shelly/integrationpluginshelly.cpp index 3b0fca36..94da8ced 100644 --- a/shelly/integrationpluginshelly.cpp +++ b/shelly/integrationpluginshelly.cpp @@ -208,19 +208,28 @@ void IntegrationPluginShelly::discoverThings(ThingDiscoveryInfo *info) continue; } + qCDebug(dcShelly()) << "Found shelly thing!" << entry; + ThingDescriptor descriptor(info->thingClassId(), entry.name(), entry.hostAddress().toString()); ParamList params; params << Param(m_idParamTypeMap.value(info->thingClassId()), entry.name()); + params << Param(m_usernameParamTypeMap.value(info->thingClassId()), ""); + params << Param(m_passwordParamTypeMap.value(info->thingClassId()), ""); + if (m_connectedDeviceParamTypeMap.contains(info->thingClassId())) { + params << Param(m_connectedDeviceParamTypeMap.value(info->thingClassId()), "None"); + } + if (m_connectedDevice2ParamTypeMap.contains(info->thingClassId())) { + params << Param(m_connectedDevice2ParamTypeMap.value(info->thingClassId()), "None"); + } descriptor.setParams(params); - Thing *existingThing = myThings().findByParams(params); - if (existingThing) { - descriptor.setThingId(existingThing->id()); + Things existingThings = myThings().filterByParam(m_idParamTypeMap.value(info->thingClassId()), entry.name()); + if (existingThings.count() == 1) { + qCDebug(dcShelly()) << "This shelly already exists in the system!"; + descriptor.setThingId(existingThings.first()->id()); } info->addThingDescriptor(descriptor); - qCDebug(dcShelly()) << "Found shelly thing!" << entry; - } info->finish(Thing::ThingErrorNoError);