Fix timer clean up on things removed and code cleaning
parent
6eaa507bbc
commit
bfd5e936f1
|
|
@ -103,17 +103,19 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
|
|||
} else if ((thing->thingClassId() == inverterThingClassId) ||
|
||||
(thing->thingClassId() == meterThingClassId) ||
|
||||
(thing->thingClassId() == storageThingClassId)) {
|
||||
|
||||
Thing *loggerThing = myThings().findById(thing->parentId());
|
||||
if (!loggerThing) {
|
||||
qCWarning(dcFronius()) << "Could not find Logger Thing for thing " << thing->name();
|
||||
return info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
||||
}
|
||||
|
||||
if (!loggerThing->setupComplete()) {
|
||||
//wait for the parent to finish the setup process
|
||||
connect(loggerThing, &Thing::setupStatusChanged, info, [this, info, loggerThing] {
|
||||
|
||||
if (loggerThing->setupComplete())
|
||||
if (loggerThing->setupComplete()) {
|
||||
setupChild(info, loggerThing);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
|
@ -163,22 +165,18 @@ void IntegrationPluginFronius::thingRemoved(Thing *thing)
|
|||
FroniusLogger *logger = m_froniusLoggers.key(thing);
|
||||
m_froniusLoggers.remove(logger);
|
||||
logger->deleteLater();
|
||||
return;
|
||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
||||
FroniusInverter *inverter = m_froniusInverters.key(thing);
|
||||
m_froniusInverters.remove(inverter);
|
||||
inverter->deleteLater();
|
||||
return;
|
||||
} else if (thing->thingClassId() == meterThingClassId) {
|
||||
FroniusMeter *meter = m_froniusMeters.key(thing);
|
||||
m_froniusMeters.remove(meter);
|
||||
meter->deleteLater();
|
||||
return;
|
||||
} else if (thing->thingClassId() == storageThingClassId) {
|
||||
FroniusStorage *storage = m_froniusStorages.key(thing);
|
||||
m_froniusStorages.remove(storage);
|
||||
storage->deleteLater();
|
||||
return;
|
||||
} else {
|
||||
Q_ASSERT_X(false, "thingRemoved", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
}
|
||||
|
|
@ -197,7 +195,6 @@ void IntegrationPluginFronius::executeAction(ThingActionInfo *info)
|
|||
qCDebug(dcFronius()) << "Execute action" << thing->name() << action.actionTypeId().toString();
|
||||
|
||||
if (thing->thingClassId() == dataloggerThingClassId) {
|
||||
|
||||
if (action.actionTypeId() == dataloggerSearchDevicesActionTypeId) {
|
||||
searchNewThings(m_froniusLoggers.key(thing));
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
|
|
@ -297,7 +294,6 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
|||
});
|
||||
} else {
|
||||
Q_ASSERT_X(false, "updateThingState", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -333,7 +329,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
|||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
qCWarning(dcFronius()) << "Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -342,6 +338,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
|||
|
||||
// Check reply information
|
||||
QVariantMap bodyMap = jsonDoc.toVariant().toMap().value("Body").toMap();
|
||||
qCDebug(dcFronius()) << "System:" << qUtf8Printable(QJsonDocument::fromVariant(bodyMap).toJson(QJsonDocument::Indented));
|
||||
|
||||
// Parse reply for inverters at the host address
|
||||
QVariantMap inverterMap = bodyMap.value("Data").toMap().value("Inverter").toMap();
|
||||
|
|
@ -409,7 +406,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
|||
});
|
||||
}
|
||||
|
||||
bool IntegrationPluginFronius::thingExists(ParamTypeId thingParamId, QString thingId)
|
||||
bool IntegrationPluginFronius::thingExists(const ParamTypeId &thingParamId, QString thingId)
|
||||
{
|
||||
foreach(Thing *thing, myThings()) {
|
||||
if (thing->paramValue(thingParamId).toString() == thingId) {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ private:
|
|||
void updateThingStates(Thing *thing);
|
||||
|
||||
void searchNewThings(FroniusLogger *logger);
|
||||
bool thingExists(ParamTypeId thingParamId, QString thingId);
|
||||
bool thingExists(const ParamTypeId &thingParamId, QString thingId);
|
||||
|
||||
void setupChild(ThingSetupInfo *info, Thing *parentThing);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue