Amperfied: Update EV charger interface and add full charging current resolution

master
Simon Stürz 2025-12-22 14:42:43 +01:00
parent a309aafa0c
commit 9122fc5144
2 changed files with 21 additions and 17 deletions

View File

@ -201,7 +201,7 @@ void IntegrationPluginAmperfied::executeAction(ThingActionInfo *info)
if (info->action().actionTypeId() == energyControlPowerActionTypeId) { if (info->action().actionTypeId() == energyControlPowerActionTypeId) {
bool power = info->action().paramValue(energyControlPowerActionPowerParamTypeId).toBool(); bool power = info->action().paramValue(energyControlPowerActionPowerParamTypeId).toBool();
ModbusRtuReply *reply = connection->setChargingCurrent(power ? info->thing()->stateValue(energyControlMaxChargingCurrentStateTypeId).toUInt() * 10 : 0); ModbusRtuReply *reply = connection->setChargingCurrent(power ? static_cast<quint16>(qRound(info->thing()->stateValue(energyControlMaxChargingCurrentStateTypeId).toDouble() * 10)) : 0);
connect(reply, &ModbusRtuReply::finished, info, [info, reply, power](){ connect(reply, &ModbusRtuReply::finished, info, [info, reply, power](){
if (reply->error() == ModbusRtuReply::NoError) { if (reply->error() == ModbusRtuReply::NoError) {
info->thing()->setStateValue(energyControlPowerStateTypeId, power); info->thing()->setStateValue(energyControlPowerStateTypeId, power);
@ -216,11 +216,11 @@ void IntegrationPluginAmperfied::executeAction(ThingActionInfo *info)
if (info->action().actionTypeId() == energyControlMaxChargingCurrentActionTypeId) { if (info->action().actionTypeId() == energyControlMaxChargingCurrentActionTypeId) {
bool power = info->thing()->stateValue(energyControlPowerStateTypeId).toBool(); bool power = info->thing()->stateValue(energyControlPowerStateTypeId).toBool();
uint max = info->action().paramValue(energyControlMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toUInt() * 10; double current = qRound(info->action().paramValue(energyControlMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toDouble() * 10) / 10.0;
ModbusRtuReply *reply = connection->setChargingCurrent(power ? max : 0); ModbusRtuReply *reply = connection->setChargingCurrent(power ? static_cast<quint16>(qRound(current * 10)) : 0);
connect(reply, &ModbusRtuReply::finished, info, [info, reply, max](){ connect(reply, &ModbusRtuReply::finished, info, [info, reply, current](){
if (reply->error() == ModbusRtuReply::NoError) { if (reply->error() == ModbusRtuReply::NoError) {
info->thing()->setStateValue(energyControlMaxChargingCurrentStateTypeId, max / 10); info->thing()->setStateValue(energyControlMaxChargingCurrentStateTypeId, current);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} else { } else {
qCWarning(dcAmperfied()) << "Error setting power:" << reply->error() << reply->errorString(); qCWarning(dcAmperfied()) << "Error setting power:" << reply->error() << reply->errorString();
@ -241,8 +241,8 @@ void IntegrationPluginAmperfied::executeAction(ThingActionInfo *info)
if (actionType.name() == "power") { if (actionType.name() == "power") {
bool power = info->action().paramValue(actionType.paramTypes().findByName("power").id()).toBool(); bool power = info->action().paramValue(actionType.paramTypes().findByName("power").id()).toBool();
uint max = info->thing()->stateValue("maxChargingCurrent").toUInt(); double current = info->thing()->stateValue("maxChargingCurrent").toDouble();
QModbusReply *reply = connection->setChargingCurrent(power ? max * 10 : 0); QModbusReply *reply = connection->setChargingCurrent(power ? static_cast<quint16>(qRound(current * 10)) : 0);
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("power", power); info->thing()->setStateValue("power", power);
@ -254,11 +254,11 @@ void IntegrationPluginAmperfied::executeAction(ThingActionInfo *info)
}); });
} else if (actionType.name() == "maxChargingCurrent") { } else if (actionType.name() == "maxChargingCurrent") {
bool power = info->thing()->stateValue("power").toBool(); bool power = info->thing()->stateValue("power").toBool();
uint max = info->action().paramValue(actionType.paramTypes().findByName("maxChargingCurrent").id()).toUInt(); double current = info->action().paramValue(actionType.paramTypes().findByName("maxChargingCurrent").id()).toDouble();
QModbusReply *reply = connection->setChargingCurrent(power ? max * 10 : 0); QModbusReply *reply = connection->setChargingCurrent(power ?static_cast<quint16>(qRound(current * 10)): 0);
connect(reply, &QModbusReply::finished, info, [info, reply, max](){ connect(reply, &QModbusReply::finished, info, [info, reply, current](){
if (reply->error() == QModbusDevice::NoError) { if (reply->error() == QModbusDevice::NoError) {
info->thing()->setStateValue("maxChargingCurrent", max / 10); info->thing()->setStateValue("maxChargingCurrent", current);
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} else { } else {
qCWarning(dcAmperfied()) << "Error setting power:" << reply->error() << reply->errorString(); qCWarning(dcAmperfied()) << "Error setting power:" << reply->error() << reply->errorString();
@ -357,7 +357,7 @@ void IntegrationPluginAmperfied::setupRtuConnection(ThingSetupInfo *info)
thing->setStateValue(energyControlPowerStateTypeId, false); thing->setStateValue(energyControlPowerStateTypeId, false);
} else { } else {
thing->setStateValue(energyControlPowerStateTypeId, true); thing->setStateValue(energyControlPowerStateTypeId, true);
thing->setStateValue(energyControlMaxChargingCurrentStateTypeId, connection->chargingCurrent() / 10); thing->setStateValue(energyControlMaxChargingCurrentStateTypeId, connection->chargingCurrent() / 10.0);
} }
thing->setStateMinMaxValues(energyControlMaxChargingCurrentStateTypeId, connection->minChargingCurrent(), connection->maxChargingCurrent()); thing->setStateMinMaxValues(energyControlMaxChargingCurrentStateTypeId, connection->minChargingCurrent(), connection->maxChargingCurrent());
thing->setStateValue(energyControlCurrentPowerStateTypeId, connection->currentPower()); thing->setStateValue(energyControlCurrentPowerStateTypeId, connection->currentPower());
@ -446,7 +446,7 @@ void IntegrationPluginAmperfied::setupTcpConnection(ThingSetupInfo *info)
thing->setStateValue("power", false); thing->setStateValue("power", false);
} else { } else {
thing->setStateValue("power", true); thing->setStateValue("power", true);
thing->setStateValue("maxChargingCurrent", connection->chargingCurrent() / 10); thing->setStateValue("maxChargingCurrent", connection->chargingCurrent() / 10.0);
} }
thing->setStateMinMaxValues("maxChargingCurrent", connection->minChargingCurrent(), connection->maxChargingCurrent()); thing->setStateMinMaxValues("maxChargingCurrent", connection->minChargingCurrent(), connection->maxChargingCurrent());
thing->setStateValue("currentPower", connection->currentPower()); thing->setStateValue("currentPower", connection->currentPower());

View File

@ -98,10 +98,11 @@
"name": "maxChargingCurrent", "name": "maxChargingCurrent",
"displayName": "Maximum charging current", "displayName": "Maximum charging current",
"displayNameAction": "Set maximum charging current", "displayNameAction": "Set maximum charging current",
"type": "uint", "type": "double",
"unit": "Ampere", "unit": "Ampere",
"minValue": 6, "minValue": 6,
"maxValue": 32, "maxValue": 32,
"stepSize": 0.1,
"defaultValue": 6, "defaultValue": 6,
"writable": true "writable": true
}, },
@ -212,10 +213,11 @@
"name": "maxChargingCurrent", "name": "maxChargingCurrent",
"displayName": "Maximum charging current", "displayName": "Maximum charging current",
"displayNameAction": "Set maximum charging current", "displayNameAction": "Set maximum charging current",
"type": "uint", "type": "double",
"unit": "Ampere", "unit": "Ampere",
"minValue": 6, "minValue": 6,
"maxValue": 32, "maxValue": 32,
"stepSize": 0.1,
"defaultValue": 6, "defaultValue": 6,
"writable": true "writable": true
}, },
@ -337,10 +339,11 @@
"name": "maxChargingCurrent", "name": "maxChargingCurrent",
"displayName": "Maximum charging current", "displayName": "Maximum charging current",
"displayNameAction": "Set maximum charging current", "displayNameAction": "Set maximum charging current",
"type": "uint", "type": "double",
"unit": "Ampere", "unit": "Ampere",
"minValue": 6, "minValue": 6,
"maxValue": 32, "maxValue": 32,
"stepSize": 0.1,
"defaultValue": 6, "defaultValue": 6,
"writable": true "writable": true
}, },
@ -462,10 +465,11 @@
"name": "maxChargingCurrent", "name": "maxChargingCurrent",
"displayName": "Maximum charging current", "displayName": "Maximum charging current",
"displayNameAction": "Set maximum charging current", "displayNameAction": "Set maximum charging current",
"type": "uint", "type": "double",
"unit": "Ampere", "unit": "Ampere",
"minValue": 6, "minValue": 6,
"maxValue": 32, "maxValue": 32,
"stepSize": 0.1,
"defaultValue": 6, "defaultValue": 6,
"writable": true "writable": true
}, },