Implement action execution

master
Simon Stürz 2025-06-17 16:37:29 +02:00
parent 09200b2da1
commit 85e108c93a
5 changed files with 115 additions and 2 deletions

View File

@ -30,7 +30,9 @@
#include "integrationplugineverest.h"
#include "plugininfo.h"
#include "mqtt/everestmqttdiscovery.h"
#include "jsonrpc/everestevse.h"
#include "jsonrpc/everestjsonrpcdiscovery.h"
#include <network/networkdevicediscovery.h>
@ -470,9 +472,78 @@ void IntegrationPluginEverest::executeAction(ThingActionInfo *info)
return;
}
if (info->action().actionTypeId() == everestChargerAcPowerActionTypeId) {
bool power = info->action().paramValue(everestChargerAcPowerActionPowerParamTypeId).toBool();
qCDebug(dcEverest()) << "Execute power action" << power;
EverestJsonRpcReply *reply = evse->setChargingAllowed(power) ;
connect(reply, &EverestJsonRpcReply::finished, reply, &EverestJsonRpcReply::deleteLater);
connect(reply, &EverestJsonRpcReply::finished, this, [info, reply, power](){
if (reply->error()) {
qCWarning(dcEverest()) << "Execute action reply finished with error" << reply->error();
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
QVariantMap result = reply->response().value("result").toMap();
EverestJsonRpcClient::ResponseError error = EverestJsonRpcClient::parseResponseError(result.value("error").toString());
if (error) {
qCWarning(dcEverest()) << "Execute action reply finished with an error" << reply->method() << error;
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
info->thing()->setStateValue(everestChargerAcCurrentPowerStateTypeId, power);
info->finish(Thing::ThingErrorNoError);
});
} else if (info->action().actionTypeId() == everestChargerAcMaxChargingCurrentActionTypeId) {
double current = info->action().paramValue(everestChargerAcMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toDouble();
qCDebug(dcEverest()) << "Execute action set max charging current" << current << "[A]";
EverestJsonRpcReply *reply = evse->setACChargingCurrent(current) ;
connect(reply, &EverestJsonRpcReply::finished, reply, &EverestJsonRpcReply::deleteLater);
connect(reply, &EverestJsonRpcReply::finished, this, [info, reply, current](){
if (reply->error()) {
qCWarning(dcEverest()) << "Execute action reply finished with error" << reply->error();
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
QVariantMap result = reply->response().value("result").toMap();
EverestJsonRpcClient::ResponseError error = EverestJsonRpcClient::parseResponseError(result.value("error").toString());
if (error) {
qCWarning(dcEverest()) << "Execute action reply finished with an error" << reply->method() << error;
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
info->thing()->setStateValue(everestChargerAcMaxChargingCurrentStateTypeId, current);
info->finish(Thing::ThingErrorNoError);
});
} else if (info->action().actionTypeId() == everestChargerAcDesiredPhaseCountActionTypeId) {
int phaseCount = info->action().paramValue(everestChargerAcDesiredPhaseCountActionDesiredPhaseCountParamTypeId).toInt();
qCDebug(dcEverest()) << "Execute action set phase count" << phaseCount;
EverestJsonRpcReply *reply = evse->setACChargingPhaseCount(phaseCount);
connect(reply, &EverestJsonRpcReply::finished, reply, &EverestJsonRpcReply::deleteLater);
connect(reply, &EverestJsonRpcReply::finished, this, [info, reply, phaseCount](){
if (reply->error()) {
qCWarning(dcEverest()) << "Execute action reply finished with error" << reply->error();
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
QVariantMap result = reply->response().value("result").toMap();
EverestJsonRpcClient::ResponseError error = EverestJsonRpcClient::parseResponseError(result.value("error").toString());
if (error) {
qCWarning(dcEverest()) << "Execute action reply finished with an error" << reply->method() << error;
info->finish(Thing::ThingErrorHardwareFailure);
return;
}
info->thing()->setStateValue(everestChargerAcDesiredPhaseCountStateTypeId, phaseCount);
info->finish(Thing::ThingErrorNoError);
});
}
return;
}

View File

@ -59,6 +59,20 @@ int EverestEvse::index() const
return m_index;
}
EverestJsonRpcReply *EverestEvse::setChargingAllowed(bool allowed)
{
return m_client->evseSetChargingAllowed(m_index, allowed);
}
EverestJsonRpcReply *EverestEvse::setACChargingCurrent(double current)
{
return m_client->evseSetACChargingCurrent(m_index, current);
}
EverestJsonRpcReply *EverestEvse::setACChargingPhaseCount(int phaseCount)
{
return m_client->evseSetACChargingPhaseCount(m_index, phaseCount);
}
void EverestEvse::initialize()
{
@ -156,8 +170,8 @@ void EverestEvse::evaluateInitFinished(EverestJsonRpcReply *reply)
m_thing->setStateValue("connected", true);
processEvseStatus();
processHardwareCapabilities();
}
}
void EverestEvse::processEvseStatus()

View File

@ -43,7 +43,9 @@ public:
int index() const;
signals:
EverestJsonRpcReply *setChargingAllowed(bool allowed);
EverestJsonRpcReply *setACChargingCurrent(double current);
EverestJsonRpcReply *setACChargingPhaseCount(int phaseCount);
private:
EverestJsonRpcClient *m_client = nullptr;

View File

@ -221,6 +221,30 @@ EverestJsonRpcReply *EverestJsonRpcClient::evseSetChargingAllowed(int evseIndex,
return reply;
}
EverestJsonRpcReply *EverestJsonRpcClient::evseSetACChargingCurrent(int evseIndex, double current)
{
QVariantMap params;
params.insert("evse_index", evseIndex);
params.insert("max_current", current);
EverestJsonRpcReply *reply = new EverestJsonRpcReply(m_commandId, "EVSE.SetACChargingCurrent", params, this);
qCDebug(dcEverest()) << "Calling" << reply->method() << params;
sendRequest(reply);
return reply;
}
EverestJsonRpcReply *EverestJsonRpcClient::evseSetACChargingPhaseCount(int evseIndex, int phaseCount)
{
QVariantMap params;
params.insert("evse_index", evseIndex);
params.insert("phase_count", phaseCount);
EverestJsonRpcReply *reply = new EverestJsonRpcReply(m_commandId, "EVSE.SetACChargingPhaseCount", params, this);
qCDebug(dcEverest()) << "Calling" << reply->method() << params;
sendRequest(reply);
return reply;
}
EverestJsonRpcClient::ResponseError EverestJsonRpcClient::parseResponseError(const QString &responseErrorString)
{
QMetaEnum metaEnum = QMetaEnum::fromType<ResponseError>();

View File

@ -182,6 +182,8 @@ public:
EverestJsonRpcReply *evseGetMeterData(int evseIndex);
EverestJsonRpcReply *evseSetChargingAllowed(int evseIndex, bool allowed);
EverestJsonRpcReply *evseSetACChargingCurrent(int evseIndex, double current);
EverestJsonRpcReply *evseSetACChargingPhaseCount(int evseIndex, int phaseCount);
// API parser methods