Fix http updating for goe

This commit is contained in:
Simon Stürz 2021-09-30 18:08:25 +02:00
parent 508f1f4be8
commit 2807cd970f

View File

@ -130,12 +130,15 @@ void IntegrationPluginGoECharger::setupThing(ThingSetupInfo *info)
QVariantMap statusMap = jsonDoc.toVariant().toMap(); QVariantMap statusMap = jsonDoc.toVariant().toMap();
if (thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) { if (thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) {
// Verify mqtt client and set it up // Verify mqtt client and set it up
qCDebug(dcGoECharger()) << "Setup using MQTT connection for" << thing;
QHostAddress address = QHostAddress(thing->paramValue(goeHomeThingIpAddressParamTypeId).toString()); QHostAddress address = QHostAddress(thing->paramValue(goeHomeThingIpAddressParamTypeId).toString());
setupMqttChannel(info, address, statusMap); setupMqttChannel(info, address, statusMap);
} else { } else {
// Since we are not using mqtt, we are done with the setup, the refresh timer will be configured in post setup // Since we are not using mqtt, we are done with the setup, the refresh timer will be configured in post setup
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
qCDebug(dcGoECharger()) << "Setup using HTTP finished successfully";
update(thing, statusMap); update(thing, statusMap);
thing->setStateValue(goeHomeConnectedStateTypeId, true);
} }
}); });
return; return;
@ -148,11 +151,12 @@ void IntegrationPluginGoECharger::postSetupThing(Thing *thing)
{ {
if (thing->thingClassId() == goeHomeThingClassId) { if (thing->thingClassId() == goeHomeThingClassId) {
// Set up refresh timer if needed and if we are not using mqtt // Set up refresh timer if needed and if we are not using mqtt
if (thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) { if (!thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) {
if (!m_refreshTimer) { if (!m_refreshTimer) {
m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(4); m_refreshTimer = hardwareManager()->pluginTimerManager()->registerTimer(4);
connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginGoECharger::refreshHttp); connect(m_refreshTimer, &PluginTimer::timeout, this, &IntegrationPluginGoECharger::refreshHttp);
m_refreshTimer->start(); m_refreshTimer->start();
qCDebug(dcGoECharger()) << "Enable HTTP refresh timer...";
} }
} }
} }
@ -667,7 +671,7 @@ void IntegrationPluginGoECharger::refreshHttp()
if (thing->thingClassId() != goeHomeThingClassId) if (thing->thingClassId() != goeHomeThingClassId)
continue; continue;
// Poll thing which is not using mqtt // Poll thing which if not using mqtt
if (!thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) { if (!thing->paramValue(goeHomeThingUseMqttParamTypeId).toBool()) {
qCDebug(dcGoECharger()) << "Refresh HTTP status from" << thing; qCDebug(dcGoECharger()) << "Refresh HTTP status from" << thing;
QNetworkReply *reply = hardwareManager()->networkManager()->get(buildStatusRequest(thing)); QNetworkReply *reply = hardwareManager()->networkManager()->get(buildStatusRequest(thing));