Fix discovery, update documentation and debug prints according to review

master
Simon Stürz 2022-08-10 12:13:36 +02:00
parent 9996d2db9f
commit 90a6c87e5a
4 changed files with 9 additions and 28 deletions

View File

@ -2,12 +2,11 @@
nymea plugin for go-eCharger smart wallbox for electic vehicles. 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 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. 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 Please note that that using the `MQTT interface` for connecting, may prevent other applications or services to connect to the go-eCharger wallbox.
reconfiguration trough the clients.
The preferred way of communicating would be MQTT (API V2), default is HTTP (API V1). The preferred way of communicating would be MQTT (API V2), default is HTTP (API V1).

View File

@ -39,12 +39,7 @@ GoeDiscovery::GoeDiscovery(NetworkAccessManager *networkAccessManager, NetworkDe
m_networkAccessManager(networkAccessManager), m_networkAccessManager(networkAccessManager),
m_networkDeviceDiscovery(networkDeviceDiscovery) 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() GoeDiscovery::~GoeDiscovery()
@ -58,7 +53,6 @@ void GoeDiscovery::startDiscovery()
// Clean up // Clean up
m_discoveryResults.clear(); m_discoveryResults.clear();
m_verifiedNetworkDeviceInfos.clear(); m_verifiedNetworkDeviceInfos.clear();
m_gracePeriodTimer.stop();
m_startDateTime = QDateTime::currentDateTime(); m_startDateTime = QDateTime::currentDateTime();
@ -90,7 +84,10 @@ void GoeDiscovery::startDiscovery()
// If there might be some response after the grace period time, // 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... // we don't care any more since there might just waiting for some timeouts...
// If there would be a device, it would have responded. // 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..."; 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 { } else {
qCDebug(dcGoECharger()) << "Discovery:" << networkDeviceInfo.address().toString() << "API V2 verification returned JSON data but not the right one. Continue..."; 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() void GoeDiscovery::cleanupPendingReplies()
{ {
foreach (QNetworkReply *reply, m_pendingReplies) { foreach (QNetworkReply *reply, m_pendingReplies) {
@ -253,7 +238,6 @@ void GoeDiscovery::finishDiscovery()
{ {
qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_startDateTime.toMSecsSinceEpoch(); 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"); 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(); cleanupPendingReplies();
emit discoveryFinished(); emit discoveryFinished();
} }

View File

@ -67,7 +67,6 @@ signals:
private: private:
QDateTime m_startDateTime; QDateTime m_startDateTime;
QTimer m_gracePeriodTimer;
NetworkAccessManager *m_networkAccessManager = nullptr; NetworkAccessManager *m_networkAccessManager = nullptr;
NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr; NetworkDeviceDiscovery *m_networkDeviceDiscovery = nullptr;
NetworkDeviceDiscoveryReply *m_discoveryReply = nullptr; NetworkDeviceDiscoveryReply *m_discoveryReply = nullptr;
@ -82,7 +81,6 @@ private slots:
void checkNetworkDeviceApiV1(const NetworkDeviceInfo &networkDeviceInfo); void checkNetworkDeviceApiV1(const NetworkDeviceInfo &networkDeviceInfo);
void checkNetworkDeviceApiV2(const NetworkDeviceInfo &networkDeviceInfo); void checkNetworkDeviceApiV2(const NetworkDeviceInfo &networkDeviceInfo);
void verifyDiscoveryFinished();
void cleanupPendingReplies(); void cleanupPendingReplies();
void finishDiscovery(); void finishDiscovery();

View File

@ -103,7 +103,7 @@ void IntegrationPluginGoECharger::discoverThings(ThingDiscoveryInfo *info)
void IntegrationPluginGoECharger::setupThing(ThingSetupInfo *info) void IntegrationPluginGoECharger::setupThing(ThingSetupInfo *info)
{ {
Thing *thing = info->thing(); 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()); MacAddress macAddress = MacAddress(thing->paramValue(goeHomeThingMacAddressParamTypeId).toString());
if (!macAddress.isValid()) { if (!macAddress.isValid()) {