Improve connects in setupThing

master
l.heizinger 2022-02-22 10:17:18 +01:00 committed by Simon Stürz
parent 3d3269b6e7
commit 662cb212c0
1 changed files with 14 additions and 14 deletions

View File

@ -101,7 +101,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
StiebelEltronModbusConnection *connection = StiebelEltronModbusConnection *connection =
new StiebelEltronModbusConnection(address, port, slaveId, this); new StiebelEltronModbusConnection(address, port, slaveId, this);
connect(connection, &StiebelEltronModbusConnection::connectionStateChanged, this, connect(connection, &StiebelEltronModbusConnection::connectionStateChanged, thing,
[thing, connection](bool status) { [thing, connection](bool status) {
qCDebug(dcStiebelEltron()) << "Connected changed to" << status << "for" << thing; qCDebug(dcStiebelEltron()) << "Connected changed to" << status << "for" << thing;
if (status) { if (status) {
@ -111,28 +111,28 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronConnectedStateTypeId, status); thing->setStateValue(stiebelEltronConnectedStateTypeId, status);
}); });
connect(connection, &StiebelEltronModbusConnection::outdoorTemperatureChanged, this, connect(connection, &StiebelEltronModbusConnection::outdoorTemperatureChanged, thing,
[thing](float outdoorTemperature) { [thing](float outdoorTemperature) {
qCDebug(dcStiebelEltron()) qCDebug(dcStiebelEltron())
<< thing << "outdoor temperature changed" << outdoorTemperature << "°C"; << thing << "outdoor temperature changed" << outdoorTemperature << "°C";
thing->setStateValue(stiebelEltronOutdoorTemperatureStateTypeId, outdoorTemperature); thing->setStateValue(stiebelEltronOutdoorTemperatureStateTypeId, outdoorTemperature);
}); });
connect(connection, &StiebelEltronModbusConnection::flowTemperatureChanged, this, connect(connection, &StiebelEltronModbusConnection::flowTemperatureChanged, thing,
[thing](float flowTemperature) { [thing](float flowTemperature) {
qCDebug(dcStiebelEltron()) qCDebug(dcStiebelEltron())
<< thing << "flow temperature changed" << flowTemperature << "°C"; << thing << "flow temperature changed" << flowTemperature << "°C";
thing->setStateValue(stiebelEltronFlowTemperatureStateTypeId, flowTemperature); thing->setStateValue(stiebelEltronFlowTemperatureStateTypeId, flowTemperature);
}); });
connect(connection, &StiebelEltronModbusConnection::hotWaterTemperatureChanged, this, connect(connection, &StiebelEltronModbusConnection::hotWaterTemperatureChanged, thing,
[thing](float hotWaterTemperature) { [thing](float hotWaterTemperature) {
qCDebug(dcStiebelEltron()) qCDebug(dcStiebelEltron())
<< thing << "hot water temperature changed" << hotWaterTemperature << "°C"; << thing << "hot water temperature changed" << hotWaterTemperature << "°C";
thing->setStateValue(stiebelEltronHotWaterTemperatureStateTypeId, hotWaterTemperature); thing->setStateValue(stiebelEltronHotWaterTemperatureStateTypeId, hotWaterTemperature);
}); });
connect(connection, &StiebelEltronModbusConnection::storageTankTemperatureChanged, this, connect(connection, &StiebelEltronModbusConnection::storageTankTemperatureChanged, thing,
[thing](float storageTankTemperature) { [thing](float storageTankTemperature) {
qCDebug(dcStiebelEltron()) qCDebug(dcStiebelEltron())
<< thing << "Storage tank temperature changed" << storageTankTemperature << "°C"; << thing << "Storage tank temperature changed" << storageTankTemperature << "°C";
@ -140,14 +140,14 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
storageTankTemperature); storageTankTemperature);
}); });
connect(connection, &StiebelEltronModbusConnection::returnTemperatureChanged, this, connect(connection, &StiebelEltronModbusConnection::returnTemperatureChanged, thing,
[thing](float returnTemperature) { [thing](float returnTemperature) {
qCDebug(dcStiebelEltron()) qCDebug(dcStiebelEltron())
<< thing << "return temperature changed" << returnTemperature << "°C"; << thing << "return temperature changed" << returnTemperature << "°C";
thing->setStateValue(stiebelEltronReturnTemperatureStateTypeId, returnTemperature); thing->setStateValue(stiebelEltronReturnTemperatureStateTypeId, returnTemperature);
}); });
connect(connection, &StiebelEltronModbusConnection::heatingEnergyChanged, this, connect(connection, &StiebelEltronModbusConnection::heatingEnergyChanged, thing,
[thing](quint32 heatingEnergy) { [thing](quint32 heatingEnergy) {
// kWh and MWh of energy are stored in two registers an read as // kWh and MWh of energy are stored in two registers an read as
// an uint32. The following arithmetic splits the uint32 into // an uint32. The following arithmetic splits the uint32 into
@ -158,7 +158,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronHeatingEnergyStateTypeId, correctedEnergy); thing->setStateValue(stiebelEltronHeatingEnergyStateTypeId, correctedEnergy);
}); });
connect(connection, &StiebelEltronModbusConnection::hotWaterEnergyChanged, this, connect(connection, &StiebelEltronModbusConnection::hotWaterEnergyChanged, thing,
[thing](quint32 hotWaterEnergy) { [thing](quint32 hotWaterEnergy) {
// see comment in heatingEnergyChanged // see comment in heatingEnergyChanged
quint32 correctedEnergy = (hotWaterEnergy >> 16) + (hotWaterEnergy & 0xFFFF) * 1000; quint32 correctedEnergy = (hotWaterEnergy >> 16) + (hotWaterEnergy & 0xFFFF) * 1000;
@ -167,7 +167,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronHotWaterEnergyStateTypeId, correctedEnergy); thing->setStateValue(stiebelEltronHotWaterEnergyStateTypeId, correctedEnergy);
}); });
connect(connection, &StiebelEltronModbusConnection::consumedEnergyHeatingChanged, this, connect(connection, &StiebelEltronModbusConnection::consumedEnergyHeatingChanged, thing,
[thing](quint32 consumedEnergyHeatingEnergy) { [thing](quint32 consumedEnergyHeatingEnergy) {
// see comment in heatingEnergyChanged // see comment in heatingEnergyChanged
quint32 correctedEnergy = quint32 correctedEnergy =
@ -177,7 +177,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronConsumedEnergyHeatingStateTypeId, correctedEnergy); thing->setStateValue(stiebelEltronConsumedEnergyHeatingStateTypeId, correctedEnergy);
}); });
connect(connection, &StiebelEltronModbusConnection::consumedEnergyHotWaterChanged, this, connect(connection, &StiebelEltronModbusConnection::consumedEnergyHotWaterChanged, thing,
[thing](quint32 consumedEnergyHotWaterEnergy) { [thing](quint32 consumedEnergyHotWaterEnergy) {
// see comment in heatingEnergyChanged // see comment in heatingEnergyChanged
quint32 correctedEnergy = quint32 correctedEnergy =
@ -187,7 +187,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronConsumedEnergyHotWaterStateTypeId, correctedEnergy); thing->setStateValue(stiebelEltronConsumedEnergyHotWaterStateTypeId, correctedEnergy);
}); });
connect(connection, &StiebelEltronModbusConnection::operatingModeChanged, this, connect(connection, &StiebelEltronModbusConnection::operatingModeChanged, thing,
[thing](StiebelEltronModbusConnection::OperatingMode operatingMode) { [thing](StiebelEltronModbusConnection::OperatingMode operatingMode) {
qCDebug(dcStiebelEltron()) << thing << "operating mode changed " << operatingMode; qCDebug(dcStiebelEltron()) << thing << "operating mode changed " << operatingMode;
switch (operatingMode) { switch (operatingMode) {
@ -212,7 +212,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
} }
}); });
connect(connection, &StiebelEltronModbusConnection::systemStatusChanged, this, connect(connection, &StiebelEltronModbusConnection::systemStatusChanged, thing,
[thing](uint16_t systemStatus) { [thing](uint16_t systemStatus) {
qCDebug(dcStiebelEltron()) << thing << "System status changed " << systemStatus; qCDebug(dcStiebelEltron()) << thing << "System status changed " << systemStatus;
thing->setStateValue(stiebelEltronPumpOneStateTypeId, systemStatus & (1 << 0)); thing->setStateValue(stiebelEltronPumpOneStateTypeId, systemStatus & (1 << 0));
@ -229,7 +229,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
thing->setStateValue(stiebelEltronSilentMode2StateTypeId, systemStatus & (1 << 11)); thing->setStateValue(stiebelEltronSilentMode2StateTypeId, systemStatus & (1 << 11));
}); });
connect(connection, &StiebelEltronModbusConnection::sgReadyStateChanged, this, connect(connection, &StiebelEltronModbusConnection::sgReadyStateChanged, thing,
[thing](StiebelEltronModbusConnection::SmartGridState smartGridState) { [thing](StiebelEltronModbusConnection::SmartGridState smartGridState) {
qCDebug(dcStiebelEltron()) << thing << "SG Ready activation changed" << smartGridState; qCDebug(dcStiebelEltron()) << thing << "SG Ready activation changed" << smartGridState;
switch (smartGridState) { switch (smartGridState) {
@ -247,7 +247,7 @@ void IntegrationPluginStiebelEltron::setupThing(ThingSetupInfo *info) {
break; break;
} }
}); });
connect(connection, &StiebelEltronModbusConnection::sgReadyActiveChanged, this, connect(connection, &StiebelEltronModbusConnection::sgReadyActiveChanged, thing,
[thing](bool smartGridActive) { [thing](bool smartGridActive) {
qCDebug(dcStiebelEltron()) << thing << "SG Ready activation changed" << smartGridActive; qCDebug(dcStiebelEltron()) << thing << "SG Ready activation changed" << smartGridActive;
thing->setStateValue(stiebelEltronSgReadyActiveStateTypeId, smartGridActive); thing->setStateValue(stiebelEltronSgReadyActiveStateTypeId, smartGridActive);