Schrack: Fix a crash when the setup of the wallbox fails

master
Michael Zanetti 2023-07-27 13:29:38 +02:00
parent 8e32831047
commit 6701652587
1 changed files with 14 additions and 9 deletions

View File

@ -101,6 +101,10 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info)
} }
CionModbusRtuConnection *cionConnection = new CionModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), address, this); CionModbusRtuConnection *cionConnection = new CionModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), address, this);
if (!info->isInitialSetup()) {
m_cionConnections.insert(thing, cionConnection);
info->finish(Thing::ThingErrorNoError);
}
connect(cionConnection, &CionModbusRtuConnection::reachableChanged, thing, [cionConnection, thing](bool reachable){ connect(cionConnection, &CionModbusRtuConnection::reachableChanged, thing, [cionConnection, thing](bool reachable){
qCDebug(dcSchrack()) << "Reachable state changed" << reachable; qCDebug(dcSchrack()) << "Reachable state changed" << reachable;
@ -112,15 +116,16 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info)
}); });
connect(cionConnection, &CionModbusRtuConnection::initializationFinished, info, [=](bool success){ connect(cionConnection, &CionModbusRtuConnection::initializationFinished, info, [=](bool success){
qCDebug(dcSchrack()) << "Initialisation finsihed" << success; qCDebug(dcSchrack()) << "Initialisation finished" << success << "DIP switche states:" << cionConnection->dipSwitches();
if (success) { if (info->isInitialSetup()) {
qCDebug(dcSchrack) << "DIP switche states:" << cionConnection->dipSwitches(); if (success) {
m_cionConnections.insert(thing, cionConnection); m_cionConnections.insert(thing, cionConnection);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
info->thing()->setStateValue(cionCurrentVersionStateTypeId, cionConnection->firmwareVersion()); info->thing()->setStateValue(cionCurrentVersionStateTypeId, cionConnection->firmwareVersion());
} else { } else {
delete cionConnection; delete cionConnection;
info->finish(Thing::ThingErrorHardwareNotAvailable); info->finish(Thing::ThingErrorHardwareNotAvailable);
}
} }
}); });