Mennekes: Fix amtron ECU power action handling

master
Michael Zanetti 2023-06-25 13:52:03 +02:00
parent 8e32831047
commit 2d093fb064
1 changed files with 9 additions and 2 deletions

View File

@ -305,9 +305,13 @@ void IntegrationPluginMennekes::executeAction(ThingActionInfo *info)
if (info->thing()->thingClassId() == amtronECUThingClassId) { if (info->thing()->thingClassId() == amtronECUThingClassId) {
AmtronECUModbusTcpConnection *amtronECUConnection = m_amtronECUConnections.value(info->thing()); AmtronECUModbusTcpConnection *amtronECUConnection = m_amtronECUConnections.value(info->thing());
if (info->action().actionTypeId() == amtronECUPowerActionTypeId) { if (info->action().actionTypeId() == amtronECUPowerActionTypeId) {
bool power = info->action().paramValue(amtronECUPowerActionPowerParamTypeId).toBool(); bool power = info->action().paramValue(amtronECUPowerActionPowerParamTypeId).toBool();
QModbusReply *reply = amtronECUConnection->setHemsCurrentLimit(power ? info->thing()->stateValue(amtronECUMaxChargingCurrentStateTypeId).toUInt() : 0); int maxChargingCurrent = info->thing()->stateValue(amtronECUMaxChargingCurrentStateTypeId).toUInt();
int effectiveCurrent = power ? maxChargingCurrent : 0;
qCInfo(dcMennekes()) << "Executing power action:" << power << "max current:" << maxChargingCurrent << "-> effective current" << effectiveCurrent;
QModbusReply *reply = amtronECUConnection->setHemsCurrentLimit(effectiveCurrent);
connect(reply, &QModbusReply::finished, info, [info, reply, power](){ connect(reply, &QModbusReply::finished, info, [info, reply, power](){
if (reply->error() == QModbusDevice::NoError) { if (reply->error() == QModbusDevice::NoError) {
info->thing()->setStateValue(amtronECUPowerStateTypeId, power); info->thing()->setStateValue(amtronECUPowerStateTypeId, power);
@ -319,8 +323,11 @@ void IntegrationPluginMennekes::executeAction(ThingActionInfo *info)
}); });
} }
if (info->action().actionTypeId() == amtronECUMaxChargingCurrentActionTypeId) { if (info->action().actionTypeId() == amtronECUMaxChargingCurrentActionTypeId) {
bool power = info->thing()->stateValue(amtronECUPowerStateTypeId).toBool();
int maxChargingCurrent = info->action().paramValue(amtronECUMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toInt(); int maxChargingCurrent = info->action().paramValue(amtronECUMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toInt();
QModbusReply *reply = amtronECUConnection->setHemsCurrentLimit(maxChargingCurrent); int effectiveCurrent = power ? maxChargingCurrent : 0;
qCInfo(dcMennekes()) << "Executing max current action:" << maxChargingCurrent << "Power is" << power << "-> effective:" << effectiveCurrent;
QModbusReply *reply = amtronECUConnection->setHemsCurrentLimit(effectiveCurrent);
connect(reply, &QModbusReply::finished, info, [info, reply, maxChargingCurrent](){ connect(reply, &QModbusReply::finished, info, [info, reply, maxChargingCurrent](){
if (reply->error() == QModbusDevice::NoError) { if (reply->error() == QModbusDevice::NoError) {
info->thing()->setStateValue(amtronECUMaxChargingCurrentStateTypeId, maxChargingCurrent); info->thing()->setStateValue(amtronECUMaxChargingCurrentStateTypeId, maxChargingCurrent);