From 9070a2b87853eb58e090252eb57886fd1616748c Mon Sep 17 00:00:00 2001 From: Bruce Eckstein Date: Wed, 3 Nov 2021 15:52:51 -0400 Subject: [PATCH] removed m_garadgetconnect --- garadget/integrationplugingaradget.cpp | 27 +++++++++++--------------- garadget/integrationplugingaradget.h | 1 - 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/garadget/integrationplugingaradget.cpp b/garadget/integrationplugingaradget.cpp index e3af1c59..50e1c1eb 100644 --- a/garadget/integrationplugingaradget.cpp +++ b/garadget/integrationplugingaradget.cpp @@ -69,34 +69,31 @@ void IntegrationPluginGaradget::setupThing(ThingSetupInfo *info) qCDebug(dcGaradget) << "entered is Connected" << client; subscribe(thing); } - m_lastActivityTimeStamps[thing] = QDateTime::currentDateTime(); } void IntegrationPluginGaradget::postSetupThing(Thing *thing) { - if (!m_pluginTimer) { + if (!m_pluginTimer && !myThings().isEmpty()) { QString name = thing->paramValue(garadgetThingDeviceNameParamTypeId).toString(); if (name.endsWith("/#")) { name.chop(2); } name = name + "/command"; qCDebug(dcGaradget) << "inside m_pluginTimer with" << name ; - uint updatetime = 30; + uint updatetime = 10; m_pluginTimer = hardwareManager()->pluginTimerManager()->registerTimer(updatetime); connect(m_pluginTimer, &PluginTimer::timeout, this, [=](){ - if (m_garadgetconnect == 1) { - foreach (Thing *thing, myThings()) { + foreach (Thing *thing, myThings()) { + if ((m_lastActivityTimeStamps[thing].msecsTo(QDateTime::currentDateTime()) > 1000 * updatetime) && (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true)) { + qCDebug(dcGaradget) << "disconnect garadget"; + thing->setStateValue(garadgetConnectedStateTypeId, false); + } + if (thing->stateValue(garadgetConnectedStateTypeId).toBool() == true) { m_mqttClients.value(thing)->publish(name, "get-status"); } } - uint timesinceupdate = QDateTime::currentDateTime().toTime_t() - m_lastActivityTimeStamps[thing].toTime_t(); - if ((timesinceupdate > updatetime) && (m_garadgetconnect == 1)) { - qCDebug(dcGaradget) << "disconnect garadget" << m_lastActivityTimeStamps[thing] << timesinceupdate ; - thing->setStateValue(garadgetConnectedStateTypeId, false); - m_garadgetconnect = 0; - } }); } } @@ -207,20 +204,19 @@ void IntegrationPluginGaradget::subscribe(Thing *thing) void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByteArray &payload, bool retained) { - qCDebug(dcGaradget) << "Received message from topic" << topic << "with msg" << payload << "retain flag" << retained; +// qCDebug(dcGaradget) << "Received message from topic" << topic << "with msg" << payload << "retain flag" << retained; MqttClient* client = static_cast(sender()); Thing *thing = m_mqttClients.key(client); if (!thing) { - qCWarning(dcGaradget) << "Received a publish message from a client where de don't have a matching thing"; + qCWarning(dcGaradget) << "Received a publish message from a client where de don't have a matching thing" << retained; return; } if (topic.endsWith("/status")) { if (thing->stateValue(garadgetConnectedStateTypeId) == false) { qCDebug(dcGaradget) << "Setting Garadget to connected" ; thing->setStateValue(garadgetConnectedStateTypeId, true); - m_garadgetconnect = 1; } m_lastActivityTimeStamps[thing] = QDateTime::currentDateTime(); QJsonParseError error; @@ -230,7 +226,7 @@ void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByt return; } QJsonObject jo = jsonDoc.object(); - thing->setStateValue(garadgetSignalStrengthStateTypeId, (100 + jo.value(QString("signal")).toInt()) * 2 ); + thing->setStateValue(garadgetSignalStrengthStateTypeId, (99 + jo.value(QString("signal")).toInt()) * 2 ); thing->setStateValue(garadgetSensorlevelStateTypeId, jo.value(QString("sensor")).toInt()); thing->setStateValue(garadgetBrightlevelStateTypeId, jo.value(QString("bright")).toInt()); if (jo.value(QString("status")).toString().contains(QString("stopped"))) { @@ -256,7 +252,6 @@ void IntegrationPluginGaradget::publishReceived(const QString &topic, const QByt if (topic.endsWith("/set-config")){ if ( (payload.contains("mqip")) or (payload.contains("mqpt")) ) { thing->setStateValue(garadgetConnectedStateTypeId, false); - m_garadgetconnect = 0; qCDebug(dcGaradget) << "Detected change of Broker msg - set connected to false"; } } diff --git a/garadget/integrationplugingaradget.h b/garadget/integrationplugingaradget.h index 17ebc5be..393a8bb3 100644 --- a/garadget/integrationplugingaradget.h +++ b/garadget/integrationplugingaradget.h @@ -64,7 +64,6 @@ private: PluginTimer *m_pluginTimer = nullptr; QHash m_lastActivityTimeStamps; - int m_garadgetconnect = 0; private slots: void subscribe(Thing *thing);