From c522717b17550871b3f76b5142b91363fd8afef7 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Thu, 22 Sep 2022 14:01:18 +0200 Subject: [PATCH] Schrack: Only complete the setup if reading a register actually works --- schrack/cion-registers.json | 10 ++++++++++ schrack/integrationpluginschrack.cpp | 20 +++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/schrack/cion-registers.json b/schrack/cion-registers.json index 1acffe7..19f5a53 100644 --- a/schrack/cion-registers.json +++ b/schrack/cion-registers.json @@ -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" } ] } diff --git a/schrack/integrationpluginschrack.cpp b/schrack/integrationpluginschrack.cpp index 9e4e647..a329e92 100644 --- a/schrack/integrationpluginschrack.cpp +++ b/schrack/integrationpluginschrack.cpp @@ -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)