Schrack: Only complete the setup if reading a register actually works

master
Michael Zanetti 2022-09-22 14:01:18 +02:00
parent 7c61c7ea8b
commit c522717b17
2 changed files with 29 additions and 1 deletions

View File

@ -161,6 +161,16 @@
"unit": "A",
"defaultValue": 13,
"access": "R"
},
{
"id": "dipSwitches",
"address": 700,
"size": 1,
"type": "uint16",
"registerType": "holdingRegister",
"readSchedule": "init",
"description": "DIP switch states",
"access": "R"
}
]
}

View File

@ -96,6 +96,25 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info)
CionModbusRtuConnection *cionConnection = new CionModbusRtuConnection(hardwareManager()->modbusRtuResource()->getModbusRtuMaster(uuid), address, this);
connect(cionConnection, &CionModbusRtuConnection::reachableChanged, thing, [cionConnection, thing](bool reachable){
qCDebug(dcSchrack()) << "Reachable state changed" << reachable;
if (reachable) {
cionConnection->initialize();
} else {
thing->setStateValue("connected", false);
}
});
connect(cionConnection, &CionModbusRtuConnection::initializationFinished, info, [info, cionConnection](bool success){
qCDebug(dcSchrack()) << "Initialisation finsihed" << success;
if (success) {
qCDebug(dcSchrack) << "DIP switche states:" << cionConnection->dipSwitches();
info->finish(Thing::ThingErrorNoError);
} else {
info->finish(Thing::ThingErrorHardwareNotAvailable);
}
});
connect(cionConnection, &CionModbusRtuConnection::updateFinished, thing, [cionConnection, thing](){
qCDebug(dcSchrack()) << "Update finished:" << thing->name() << cionConnection;
});
@ -183,7 +202,6 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info)
thing->setStateMinMaxValues(cionMaxChargingCurrentStateTypeId, 6, 32);
m_cionConnections.insert(thing, cionConnection);
info->finish(Thing::ThingErrorNoError);
}
void IntegrationPluginSchrack::postSetupThing(Thing *thing)