Implementation of play pause depending on action issuer
Signed-off-by: Martin Lukas <martin.lukas@chargebyte.com>master
parent
4443ff04f1
commit
5affe6614e
|
|
@ -162,27 +162,58 @@ void IntegrationPluginInro::executeAction(ThingActionInfo *info)
|
|||
|
||||
if (info->action().actionTypeId() == pantaboxPowerActionTypeId) {
|
||||
bool power = info->action().paramValue(pantaboxPowerActionPowerParamTypeId).toBool();
|
||||
qCDebug(dcInro()) << "PANTABOX: Set power" << (power ? 1 : 0);
|
||||
|
||||
QModbusReply *reply = connection->setChargingEnabled(power ? 1 : 0);
|
||||
if (!reply) {
|
||||
qCWarning(dcInro()) << "Execute action failed because the reply could not be created.";
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
if (info->action().triggeredBy() == Action::TriggeredByUser) {
|
||||
|
||||
// When power is set by user, charging is going to stop or start depending on setting
|
||||
qCDebug(dcInro()) << "PANTABOX: Set power by user" << (power ? 1 : 0);
|
||||
QModbusReply *reply = connection->setChargingEnabled(power ? 1 : 0);
|
||||
|
||||
if (!reply) {
|
||||
qCWarning(dcInro()) << "Execute action failed because the reply could not be created.";
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
connect(reply, &QModbusReply::finished, reply, &QModbusReply::deleteLater);
|
||||
connect(reply, &QModbusReply::finished, info, [info, reply, power](){
|
||||
if (reply->error() == QModbusDevice::NoError) {
|
||||
info->thing()->setStateValue(pantaboxPowerStateTypeId, power);
|
||||
qCDebug(dcInro()) << "PANTABOX: Set power by user finished successfully";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcInro()) << "Error setting power by user:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
}
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
|
||||
// When power is set to 0 by energy manager, max charging current is set to 0 otherwise take the configured max charging current
|
||||
qCDebug(dcInro()) << "PANTABOX: Pause session by energy manager";
|
||||
|
||||
quint16 chargingCurrent = power ? info->action().paramValue(pantaboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toUInt() : 0;
|
||||
QModbusReply *reply = connection->setMaxChargingCurrent(chargingCurrent);
|
||||
|
||||
if (!reply) {
|
||||
qCWarning(dcInro()) << "Execute action failed because the reply could not be created.";
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
return;
|
||||
}
|
||||
|
||||
connect(reply, &QModbusReply::finished, reply, &QModbusReply::deleteLater);
|
||||
connect(reply, &QModbusReply::finished, info, [info, reply, chargingCurrent](){
|
||||
if (reply->error() == QModbusDevice::NoError) {
|
||||
info->thing()->setStateValue(pantaboxMaxChargingCurrentStateTypeId, chargingCurrent);
|
||||
qCDebug(dcInro()) << "PANTABOX: Set max charging current finished successfully";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcInro()) << "Error setting charging current:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
connect(reply, &QModbusReply::finished, reply, &QModbusReply::deleteLater);
|
||||
connect(reply, &QModbusReply::finished, info, [info, reply, power](){
|
||||
if (reply->error() == QModbusDevice::NoError) {
|
||||
info->thing()->setStateValue(pantaboxPowerStateTypeId, power);
|
||||
qCDebug(dcInro()) << "PANTABOX: Set power finished successfully";
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcInro()) << "Error setting power:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (info->action().actionTypeId() == pantaboxMaxChargingCurrentActionTypeId) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue