From d97d4cff149e8a47dc76ea7268a6ba5de08edbc3 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Mon, 27 Jul 2020 16:27:02 +0200 Subject: [PATCH] fixed more remarks from reviewer --- fronius/froniusmeter.cpp | 4 +-- fronius/integrationpluginfronius.cpp | 43 ++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/fronius/froniusmeter.cpp b/fronius/froniusmeter.cpp index 5097a29a..7fd11271 100644 --- a/fronius/froniusmeter.cpp +++ b/fronius/froniusmeter.cpp @@ -69,7 +69,7 @@ void FroniusMeter::updateThingInfo(const QByteArray &data) QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error); if (error.error != QJsonParseError::NoError) { qCWarning(dcFronius()) << "FroniusMeter: Failed to parse JSON data" << data << ":" << error.errorString(); - pluginThing()->setStateValue(inverterConnectedStateTypeId,false); + pluginThing()->setStateValue(meterConnectedStateTypeId, false); return; } @@ -79,7 +79,7 @@ void FroniusMeter::updateThingInfo(const QByteArray &data) //Add Smart meter with following states: „PowerReal_P_Sum“, „EnergyReal_WAC_Sum_Produced“, „EnergyReal_WAC_Sum_Consumed“ - // Set the inverter thing state + // Set the meter thing state if (dataMap.contains("PowerReal_P_Sum")) { pluginThing()->setStateValue(meterCurrentPowerStateTypeId, dataMap.value("PowerReal_P_Sum").toInt()); } diff --git a/fronius/integrationpluginfronius.cpp b/fronius/integrationpluginfronius.cpp index 94295dfd..c00cf412 100644 --- a/fronius/integrationpluginfronius.cpp +++ b/fronius/integrationpluginfronius.cpp @@ -41,7 +41,8 @@ // Notes: Test IPs: 93.82.221.82 | 88.117.152.99 -IntegrationPluginFronius::IntegrationPluginFronius(QObject *parent): IntegrationPlugin(parent){ +IntegrationPluginFronius::IntegrationPluginFronius(QObject *parent): IntegrationPlugin(parent) +{ } @@ -72,7 +73,11 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info) QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl)); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, info, [this, info, thing, reply]() { + connect(reply, &QNetworkReply::finished, this, [this, info, thing, reply] { + if (!info) { + qCWarning(dcFronius()) << "Setup info vanished ignoring network reply"; + return; + } QByteArray data = reply->readAll(); if (reply->error() != QNetworkReply::NoError) { @@ -108,7 +113,12 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info) } if (!loggerThing->setupComplete()) { //wait for the parent to finish the setup process - connect(loggerThing, &Thing::setupStatusChanged, info, [this, info, loggerThing] { + connect(loggerThing, &Thing::setupStatusChanged, this, [this, info, loggerThing] { + if (!info) { + qCWarning(dcFronius()) << "Setup info vanished ignoring setup"; + return; + } + if (loggerThing->setupComplete()) setupChild(info, loggerThing); }); @@ -213,7 +223,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing) if(thing->thingClassId() == inverterThingClassId) { QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusInverters.key(thing)->updateUrl())); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() { + connect(reply, &QNetworkReply::finished, thing, [this, thing, reply]() { if (reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url(); @@ -226,7 +236,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing) }); QNetworkReply *next_reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusInverters.key(thing)->activityUrl())); connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater); - connect(next_reply, &QNetworkReply::finished, this, [this, thing, next_reply]() { + connect(next_reply, &QNetworkReply::finished, this, [this, thing, next_reply] { if (next_reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url(); return; @@ -239,7 +249,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing) } else if (thing->thingClassId() == dataloggerThingClassId) { QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusLoggers.key(thing)->updateUrl())); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() { + connect(reply, &QNetworkReply::finished, thing, [this, thing, reply]() { if (reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url(); @@ -268,7 +278,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing) } else if (thing->thingClassId() == storageThingClassId) { QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusStorages.key(thing)->updateUrl())); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() { + connect(reply, &QNetworkReply::finished, thing, [this, thing, reply]() { if (reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url(); @@ -281,8 +291,8 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing) }); QNetworkReply *next_reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusStorages.key(thing)->activityUrl())); connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater); - connect(next_reply, &QNetworkReply::finished, this, [this, thing, next_reply]() { - next_reply->deleteLater(); + connect(next_reply, &QNetworkReply::finished, thing, [this, thing, next_reply]() { + if (next_reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url(); return; @@ -438,7 +448,12 @@ void IntegrationPluginFronius::setupChild(ThingSetupInfo *info, Thing *loggerThi qCDebug(dcFronius()) << "Get Storage Data at address" << requestUrl.toString(); QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl)); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, info, [this, info, newStorage, reply]() { + connect(reply, &QNetworkReply::finished, this, [this, info, newStorage, reply]() { + + if (!info) { + qCWarning(dcFronius()) << "Setup info vanished ignoring network reply"; + return; + } QByteArray data = reply->readAll(); if (reply->error() != QNetworkReply::NoError) { @@ -478,9 +493,13 @@ void IntegrationPluginFronius::setupChild(ThingSetupInfo *info, Thing *loggerThi QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl)); connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater); - connect(reply, &QNetworkReply::finished, info, [this, info, newInverter, reply]() { + connect(reply, &QNetworkReply::finished, this, [this, info, newInverter, reply]() { + if (!info) { + qCWarning(dcFronius()) << "Setup info vanished ignoring network reply"; + return; + } + QByteArray data = reply->readAll(); - reply->deleteLater(); if (reply->error() != QNetworkReply::NoError) { qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString();