From 0d61be64fec94f3407773cf676bb7ad93f954ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 28 Sep 2022 16:49:53 +0200 Subject: [PATCH] Clean up network device discovery replies due to mechanism update --- .../integrationpluginalphainnotec.cpp | 2 ++ huawei/huaweifusionsolardiscovery.cpp | 25 +------------------ huawei/huaweifusionsolardiscovery.h | 5 ---- idm/integrationpluginidm.cpp | 1 + kostal/kostaldiscovery.cpp | 6 +---- .../integrationpluginmodbuscommander.cpp | 1 + mtec/integrationpluginmtec.cpp | 1 + .../integrationpluginstiebeleltron.cpp | 1 + sunspec/integrationpluginsunspec.cpp | 1 + webasto/integrationpluginwebasto.cpp | 1 + 10 files changed, 10 insertions(+), 34 deletions(-) diff --git a/alphainnotec/integrationpluginalphainnotec.cpp b/alphainnotec/integrationpluginalphainnotec.cpp index 0011ff4..e53bb20 100644 --- a/alphainnotec/integrationpluginalphainnotec.cpp +++ b/alphainnotec/integrationpluginalphainnotec.cpp @@ -48,7 +48,9 @@ void IntegrationPluginAlphaInnotec::discoverThings(ThingDiscoveryInfo *info) } NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ + foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) { qCDebug(dcAlphaInnotec()) << "Found" << networkDeviceInfo; diff --git a/huawei/huaweifusionsolardiscovery.cpp b/huawei/huaweifusionsolardiscovery.cpp index f27d06e..237111d 100644 --- a/huawei/huaweifusionsolardiscovery.cpp +++ b/huawei/huaweifusionsolardiscovery.cpp @@ -45,27 +45,9 @@ void HuaweiFusionSolarDiscovery::startDiscovery() { qCInfo(dcHuawei()) << "Discovery: Start searching for Huawei FusionSolar SmartDongle in the network..."; NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover(); - - // Check any already discovered infos.. - foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) { - checkNetworkDevice(networkDeviceInfo); - } - - // Immedialty check any new device gets discovered connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &HuaweiFusionSolarDiscovery::checkNetworkDevice); - - // Check what might be left on finished + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ - qCDebug(dcHuawei()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices"; - m_networkDeviceInfos = discoveryReply->networkDeviceInfos(); - qCDebug(dcHuawei()) << "Discovery: Network discovery finished. Start finishing discovery..."; - // Send a report request to nework device info not sent already... - foreach (const NetworkDeviceInfo &networkDeviceInfo, m_networkDeviceInfos) { - if (!m_verifiedNetworkDeviceInfos.contains(networkDeviceInfo)) { - checkNetworkDevice(networkDeviceInfo); - } - } - // Finish with some delay so the last added network device information objects still can be checked. QTimer::singleShot(3000, this, [this](){ qCDebug(dcHuawei()) << "Discovery: Grace period timer triggered."; @@ -81,17 +63,12 @@ NetworkDeviceInfos HuaweiFusionSolarDiscovery::discoveryResults() const void HuaweiFusionSolarDiscovery::checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo) { - if (m_verifiedNetworkDeviceInfos.contains(networkDeviceInfo)) - return; - // The dongle must have a huawei registered mac address if (!networkDeviceInfo.macAddressManufacturer().toLower().contains("huawei")) return; HuaweiFusionSolar *connection = new HuaweiFusionSolar(networkDeviceInfo.address(), m_port, m_modbusAddress, this); m_connections.append(connection); - m_verifiedNetworkDeviceInfos.append(networkDeviceInfo); - connect(connection, &HuaweiFusionSolar::reachableChanged, this, [=](bool reachable){ if (!reachable) { // Disconnected ... done with this connection diff --git a/huawei/huaweifusionsolardiscovery.h b/huawei/huaweifusionsolardiscovery.h index be3753a..27bf033 100644 --- a/huawei/huaweifusionsolardiscovery.h +++ b/huawei/huaweifusionsolardiscovery.h @@ -56,12 +56,7 @@ private: quint16 m_modbusAddress; QDateTime m_startDateTime; - - NetworkDeviceInfos m_networkDeviceInfos; - NetworkDeviceInfos m_verifiedNetworkDeviceInfos; - QList m_connections; - NetworkDeviceInfos m_discoveryResults; void checkNetworkDevice(const NetworkDeviceInfo &networkDeviceInfo); diff --git a/idm/integrationpluginidm.cpp b/idm/integrationpluginidm.cpp index 1f0790e..8913958 100644 --- a/idm/integrationpluginidm.cpp +++ b/idm/integrationpluginidm.cpp @@ -48,6 +48,7 @@ void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info) qCDebug(dcIdm()) << "Discovering network..."; NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ ThingDescriptors descriptors; qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices"; diff --git a/kostal/kostaldiscovery.cpp b/kostal/kostaldiscovery.cpp index df1e4bd..c581525 100644 --- a/kostal/kostaldiscovery.cpp +++ b/kostal/kostaldiscovery.cpp @@ -45,15 +45,11 @@ void KostalDiscovery::startDiscovery() qCInfo(dcKostal()) << "Discovery: Start searching for Kostal inverters in the network..."; NetworkDeviceDiscoveryReply *discoveryReply = m_networkDeviceDiscovery->discover(); - // Check any already discovered infos.. - // FIXME: this is not required any more once each discovery request receives it's own object getting the added signal for every info - foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) - checkNetworkDevice(networkDeviceInfo); - // Imedialty check any new device gets discovered connect(discoveryReply, &NetworkDeviceDiscoveryReply::networkDeviceInfoAdded, this, &KostalDiscovery::checkNetworkDevice); // Check what might be left on finished + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ qCDebug(dcKostal()) << "Discovery: Network discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "network devices"; m_networkDeviceInfos = discoveryReply->networkDeviceInfos(); diff --git a/modbuscommander/integrationpluginmodbuscommander.cpp b/modbuscommander/integrationpluginmodbuscommander.cpp index ec597f6..74402b5 100644 --- a/modbuscommander/integrationpluginmodbuscommander.cpp +++ b/modbuscommander/integrationpluginmodbuscommander.cpp @@ -116,6 +116,7 @@ void IntegrationPluginModbusCommander::discoverThings(ThingDiscoveryInfo *info) } NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ ThingDescriptors descriptors; qCDebug(dcModbusCommander()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices"; diff --git a/mtec/integrationpluginmtec.cpp b/mtec/integrationpluginmtec.cpp index f0452ad..52f9712 100644 --- a/mtec/integrationpluginmtec.cpp +++ b/mtec/integrationpluginmtec.cpp @@ -48,6 +48,7 @@ void IntegrationPluginMTec::discoverThings(ThingDiscoveryInfo *info) // Perform a network device discovery and filter for "go-eCharger" hosts NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) { diff --git a/stiebeleltron/integrationpluginstiebeleltron.cpp b/stiebeleltron/integrationpluginstiebeleltron.cpp index 086538a..3980d9b 100644 --- a/stiebeleltron/integrationpluginstiebeleltron.cpp +++ b/stiebeleltron/integrationpluginstiebeleltron.cpp @@ -45,6 +45,7 @@ void IntegrationPluginStiebelEltron::discoverThings(ThingDiscoveryInfo *info) { } NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=]() { foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) { qCDebug(dcStiebelEltron()) << "Found" << networkDeviceInfo; diff --git a/sunspec/integrationpluginsunspec.cpp b/sunspec/integrationpluginsunspec.cpp index f918fa4..9db35bd 100644 --- a/sunspec/integrationpluginsunspec.cpp +++ b/sunspec/integrationpluginsunspec.cpp @@ -136,6 +136,7 @@ void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info) } NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ ThingDescriptors descriptors; qCDebug(dcSunSpec()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices"; diff --git a/webasto/integrationpluginwebasto.cpp b/webasto/integrationpluginwebasto.cpp index 008c8e2..3546ddb 100644 --- a/webasto/integrationpluginwebasto.cpp +++ b/webasto/integrationpluginwebasto.cpp @@ -90,6 +90,7 @@ void IntegrationPluginWebasto::discoverThings(ThingDiscoveryInfo *info) qCDebug(dcWebasto()) << "Discover things"; NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater); connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){ ThingDescriptors descriptors; qCDebug(dcWebasto()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";