solarlog: Set energy states to 0 if not connected

master
Simon Stürz 2023-02-02 01:03:13 +01:00
parent bc059d4efd
commit 2bfebb3de9
2 changed files with 14 additions and 1 deletions

View File

@ -96,12 +96,12 @@ void IntegrationPluginSolarLog::getData(Thing *thing)
// Check HTTP status code
if (status != 200 || reply->error() != QNetworkReply::NoError) {
thing->setStateValue(solarlogConnectedStateTypeId, false);
qCWarning(dcSolarlog()) << "Request error:" << status << reply->errorString();
if (m_asyncSetup.contains(thing)) {
ThingSetupInfo *info = m_asyncSetup.take(thing);
info->finish(Thing::ThingErrorHardwareNotAvailable, tr("No Solar-Log device at given IP-Address"));
}
markThingDisconnected(thing);
return;
}
@ -143,3 +143,15 @@ void IntegrationPluginSolarLog::getData(Thing *thing)
thing->setStateValue(solarlogTotalPowerStateTypeId, (map.value(QString::number(JsonObjectNumbers::TotalPower)).toDouble()/1000.00));
});
}
void IntegrationPluginSolarLog::markThingDisconnected(Thing *thing)
{
qCDebug(dcSolarlog()) << "Resetting states of" << thing;
thing->setStateValue(solarlogConnectedStateTypeId, false);
thing->setStateValue(solarlogCurrentPowerStateTypeId, 0);
thing->setStateValue(solarlogPdcStateTypeId, 0);
thing->setStateValue(solarlogUacStateTypeId, 0);
thing->setStateValue(solarlogDcVoltageStateTypeId, 0);
thing->setStateValue(solarlogPowerUsageStateTypeId, 0);
thing->setStateValue(solarlogTotalPowerStateTypeId, 0);
}

View File

@ -78,6 +78,7 @@ private:
QHash<Thing *, ThingSetupInfo *> m_asyncSetup;
void getData(Thing *thing);
void markThingDisconnected(Thing *thing);
};
#endif // INTEGRATIONPLUGINSOLARLOG_H