From 90a6c87e5a4ca87b0e4333b2de456a627d492221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Wed, 10 Aug 2022 12:13:36 +0200 Subject: [PATCH] Fix discovery, update documentation and debug prints according to review --- goecharger/README.md | 7 +++--- goecharger/goediscovery.cpp | 26 +++++----------------- goecharger/goediscovery.h | 2 -- goecharger/integrationplugingoecharger.cpp | 2 +- 4 files changed, 9 insertions(+), 28 deletions(-) diff --git a/goecharger/README.md b/goecharger/README.md index 406e19c8..92e7d4a8 100644 --- a/goecharger/README.md +++ b/goecharger/README.md @@ -2,12 +2,11 @@ nymea plugin for go-eCharger smart wallbox for electic vehicles. -In order to make nymea work with go-e, please make sure you have enable `API V2` in the official app. +In order to integrate go-eChargers with nymea, please make sure the `API V2` is enabled in the go-eCharger app. If you are using the original go-e App or other client services to communicate with the wallbox, disable MQTT during the setup in order to make -sure all services are able to communicate with the wallbox. -There is no support for multiple MQTT clients on go-e devices, thus nymea defaults to HTTP to prevent constant -reconfiguration trough the clients. +sure all services are able to communicate with the wallbox. +Please note that that using the `MQTT interface` for connecting, may prevent other applications or services to connect to the go-eCharger wallbox. The preferred way of communicating would be MQTT (API V2), default is HTTP (API V1). diff --git a/goecharger/goediscovery.cpp b/goecharger/goediscovery.cpp index 1c98e288..4475f8c4 100644 --- a/goecharger/goediscovery.cpp +++ b/goecharger/goediscovery.cpp @@ -39,12 +39,7 @@ GoeDiscovery::GoeDiscovery(NetworkAccessManager *networkAccessManager, NetworkDe m_networkAccessManager(networkAccessManager), m_networkDeviceDiscovery(networkDeviceDiscovery) { - m_gracePeriodTimer.setSingleShot(true); - m_gracePeriodTimer.setInterval(3000); - connect(&m_gracePeriodTimer, &QTimer::timeout, this, [this](){ - qCDebug(dcGoECharger()) << "Discovery: Grace period timer triggered."; - finishDiscovery(); - }); + } GoeDiscovery::~GoeDiscovery() @@ -58,7 +53,6 @@ void GoeDiscovery::startDiscovery() // Clean up m_discoveryResults.clear(); m_verifiedNetworkDeviceInfos.clear(); - m_gracePeriodTimer.stop(); m_startDateTime = QDateTime::currentDateTime(); @@ -90,7 +84,10 @@ void GoeDiscovery::startDiscovery() // If there might be some response after the grace period time, // we don't care any more since there might just waiting for some timeouts... // If there would be a device, it would have responded. - m_gracePeriodTimer.start(); + QTimer::singleShot(3000, this, [this](){ + qCDebug(dcGoECharger()) << "Discovery: Grace period timer triggered."; + finishDiscovery(); + }); }); } @@ -176,8 +173,6 @@ void GoeDiscovery::checkNetworkDeviceApiV1(const NetworkDeviceInfo &networkDevic qCDebug(dcGoECharger()) << "Discovery:" << networkDeviceInfo.address().toString() << "API V1 verification returned JSON data but not the right one. Continue..."; } - // Check if we are done with all checks - verifyDiscoveryFinished(); }); } @@ -228,19 +223,9 @@ void GoeDiscovery::checkNetworkDeviceApiV2(const NetworkDeviceInfo &networkDevic } else { qCDebug(dcGoECharger()) << "Discovery:" << networkDeviceInfo.address().toString() << "API V2 verification returned JSON data but not the right one. Continue..."; } - - // Check if we are done with all checks - verifyDiscoveryFinished(); }); } -void GoeDiscovery::verifyDiscoveryFinished() -{ - if (!m_discoveryReply && m_verifiedNetworkDeviceInfos.count() == m_discoveredNetworkDeviceInfos.count()) { - finishDiscovery(); - } -} - void GoeDiscovery::cleanupPendingReplies() { foreach (QNetworkReply *reply, m_pendingReplies) { @@ -253,7 +238,6 @@ void GoeDiscovery::finishDiscovery() { qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch(); qCInfo(dcGoECharger()) << "Discovery: Finished the discovery process. Found" << m_discoveryResults.count() << "go-eChargers in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz"); - m_gracePeriodTimer.stop(); cleanupPendingReplies(); emit discoveryFinished(); } diff --git a/goecharger/goediscovery.h b/goecharger/goediscovery.h index 7f951f4c..1c05d8c4 100644 --- a/goecharger/goediscovery.h +++ b/goecharger/goediscovery.h @@ -67,7 +67,6 @@ signals: private: QDateTime m_startDateTime; - QTimer m_gracePeriodTimer; NetworkAccessManager *m_networkAccessManager = nullptr; NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr; NetworkDeviceDiscoveryReply *m_discoveryReply = nullptr; @@ -82,7 +81,6 @@ private slots: void checkNetworkDeviceApiV1(const NetworkDeviceInfo &networkDeviceInfo); void checkNetworkDeviceApiV2(const NetworkDeviceInfo &networkDeviceInfo); - void verifyDiscoveryFinished(); void cleanupPendingReplies(); void finishDiscovery(); diff --git a/goecharger/integrationplugingoecharger.cpp b/goecharger/integrationplugingoecharger.cpp index 2485fd99..7d7194fa 100644 --- a/goecharger/integrationplugingoecharger.cpp +++ b/goecharger/integrationplugingoecharger.cpp @@ -103,7 +103,7 @@ void IntegrationPluginGoECharger::discoverThings(ThingDiscoveryInfo *info) void IntegrationPluginGoECharger::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); - qCDebug(dcGoECharger()) << "Set up" << thing << thing->params(); + qCDebug(dcGoECharger()) << "Setting up" << thing << thing->params(); MacAddress macAddress = MacAddress(thing->paramValue(goeHomeThingMacAddressParamTypeId).toString()); if (!macAddress.isValid()) {