Merge PR #486: Keba: set limit for charging current and update to new interface definitions

This commit is contained in:
Jenkins nymea 2021-12-15 11:52:54 +01:00
commit 68cffcc68a
2 changed files with 106 additions and 81 deletions

View File

@ -127,6 +127,14 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
QHostAddress address = QHostAddress(thing->paramValue(wallboxThingIpAddressParamTypeId).toString());
// Check if we have a keba with this ip, if reconfigure the object would already been removed from the hash
foreach (KeContact *kebaConnect, m_kebaDevices.values()) {
if (kebaConnect->address() == address) {
qCWarning(dcKeba()) << "Failed to set up keba for host address" << address.toString() << "because there has already been configured a keba for this ip.";
return info->finish(Thing::ThingErrorThingInUse, QT_TR_NOOP("Already configured for this IP address."));
}
}
KeContact *keba = new KeContact(address, m_kebaDataLayer, this);
connect(keba, &KeContact::reachableChanged, this, &IntegrationPluginKeba::onConnectionChanged);
connect(keba, &KeContact::commandExecuted, this, &IntegrationPluginKeba::onCommandExecuted);
@ -149,7 +157,7 @@ void IntegrationPluginKeba::setupThing(ThingSetupInfo *info)
thing->setStateValue(wallboxFirmwareStateTypeId, report.firmware);
thing->setStateValue(wallboxSerialnumberStateTypeId, report.serialNumber);
thing->setStateValue(wallboxModelStateTypeId, report.product);
thing->setStateValue(wallboxUptimeStateTypeId, report.seconds/60);
thing->setStateValue(wallboxUptimeStateTypeId, report.seconds / 60);
m_kebaDevices.insert(thing->id(), keba);
info->finish(Thing::ThingErrorNoError);
@ -280,6 +288,8 @@ void IntegrationPluginKeba::setDeviceState(Thing *thing, KeContact::State state)
thing->setStateValue(wallboxActivityStateTypeId, "Authorization rejected");
break;
}
thing->setStateValue(wallboxChargingStateTypeId, state == KeContact::StateCharging);
}
void IntegrationPluginKeba::setDevicePlugState(Thing *thing, KeContact::PlugState plugState)
@ -421,15 +431,17 @@ void IntegrationPluginKeba::onReportTwoReceived(const KeContact::ReportTwo &repo
thing->setStateValue(wallboxError2StateTypeId, reportTwo.error2);
thing->setStateValue(wallboxSystemEnabledStateTypeId, reportTwo.enableSys);
thing->setStateValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currTimer);
thing->setStateValue(wallboxMaxChargingCurrentGeneralStateTypeId, reportTwo.currentUser);
thing->setStateValue(wallboxMaxChargingCurrentStateTypeId, qRound(reportTwo.currentUser));
thing->setStateValue(wallboxMaxChargingCurrentPercentStateTypeId, reportTwo.maxCurrentPercentage);
thing->setStateValue(wallboxMaxChargingCurrentHardwareStateTypeId, reportTwo.currentHardwareLimitation);
// Set the state limits according to the hardware limits
// FIXME: enable limits once landed
//thing->setStateMaxValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currentHardwareLimitation);
//thing->setStateMaxValue(wallboxMaxChargingCurrentGeneralStateTypeId, reportTwo.currentHardwareLimitation);
if (reportTwo.currentHardwareLimitation > 0) {
thing->setStateMaxValue(wallboxMaxChargingCurrentStateTypeId, reportTwo.currentHardwareLimitation);
} else {
// If we have no limit given, reset to the statetype limit
thing->setStateMaxValue(wallboxMaxChargingCurrentStateTypeId, thing->thingClass().getStateType(wallboxMaxChargingCurrentStateTypeId).maxValue());
}
thing->setStateValue(wallboxOutputX2StateTypeId, reportTwo.output);
thing->setStateValue(wallboxInputStateTypeId, reportTwo.input);
@ -457,20 +469,34 @@ void IntegrationPluginKeba::onReportThreeReceived(const KeContact::ReportThree &
qCDebug(dcKeba()) << " - Energy session" << reportThree.energySession << "[kWh]";
qCDebug(dcKeba()) << " - Energy total" << reportThree.energyTotal << "[kWh]";
qCDebug(dcKeba()) << " - Serial number" << reportThree.serialNumber;
qCDebug(dcKeba()) << " - Uptime" << reportThree.seconds/60 << "[min]";
qCDebug(dcKeba()) << " - Uptime" << reportThree.seconds / 60 << "[min]";
if (reportThree.serialNumber == thing->stateValue(wallboxSerialnumberStateTypeId).toString()) {
thing->setStateValue(wallboxCurrentPhase1EventTypeId, reportThree.currentPhase1);
thing->setStateValue(wallboxCurrentPhase2EventTypeId, reportThree.currentPhase2);
thing->setStateValue(wallboxCurrentPhase3EventTypeId, reportThree.currentPhase3);
thing->setStateValue(wallboxCurrentStateTypeId, reportThree.currentPhase1 + reportThree.currentPhase2 + reportThree.currentPhase3);
thing->setStateValue(wallboxVoltagePhase1EventTypeId, reportThree.voltagePhase1);
thing->setStateValue(wallboxVoltagePhase2EventTypeId, reportThree.voltagePhase2);
thing->setStateValue(wallboxVoltagePhase3EventTypeId, reportThree.voltagePhase3);
thing->setStateValue(wallboxCurrentPhaseAEventTypeId, reportThree.currentPhase1);
thing->setStateValue(wallboxCurrentPhaseBEventTypeId, reportThree.currentPhase2);
thing->setStateValue(wallboxCurrentPhaseCEventTypeId, reportThree.currentPhase3);
thing->setStateValue(wallboxVoltagePhaseAEventTypeId, reportThree.voltagePhase1);
thing->setStateValue(wallboxVoltagePhaseBEventTypeId, reportThree.voltagePhase2);
thing->setStateValue(wallboxVoltagePhaseCEventTypeId, reportThree.voltagePhase3);
thing->setStateValue(wallboxCurrentPowerStateTypeId, reportThree.power);
thing->setStateValue(wallboxSessionEnergyStateTypeId, reportThree.energySession);
thing->setStateValue(wallboxPowerFactorStateTypeId, reportThree.powerFactor);
thing->setStateValue(wallboxTotalEnergyConsumedStateTypeId, reportThree.energyTotal);
// Check how many phases are actually charging, and update the phase count only if something happens on the phases (current or power)
if (!(reportThree.currentPhase1 == 0 && reportThree.currentPhase2 == 0 && reportThree.currentPhase3 == 0)) {
uint phaseCount = 0;
if (reportThree.currentPhase1 != 0)
phaseCount += 1;
if (reportThree.currentPhase2 != 0)
phaseCount += 1;
if (reportThree.currentPhase3 != 0)
phaseCount += 1;
thing->setStateValue(wallboxPhaseCountStateTypeId, phaseCount);
}
} else {
qCWarning(dcKeba()) << "Received report but the serial number didn't match";
}
@ -579,10 +605,7 @@ void IntegrationPluginKeba::executeAction(ThingActionInfo *info)
QUuid requestId;
if (action.actionTypeId() == wallboxMaxChargingCurrentActionTypeId) {
int milliAmpere = action.param(wallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).value().toDouble() * 1000;
requestId = keba->setMaxAmpere(milliAmpere);
} else if(action.actionTypeId() == wallboxMaxChargingCurrentGeneralActionTypeId) {
int milliAmpere = action.param(wallboxMaxChargingCurrentGeneralActionMaxChargingCurrentGeneralParamTypeId).value().toDouble() * 1000;
int milliAmpere = action.param(wallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).value().toUInt() * 1000;
requestId = keba->setMaxAmpereGeneral(milliAmpere);
} else if(action.actionTypeId() == wallboxPowerActionTypeId) {
requestId = keba->enableOutput(action.param(wallboxPowerActionTypeId).value().toBool());

View File

@ -43,22 +43,6 @@
"defaultValue": false,
"cached": false
},
{
"id": "b44bc948-1234-4f87-9a22-bfb6de09df4d",
"name": "error1",
"displayName": "Error 1",
"displayNameEvent": "Error 1 changed",
"type": "int",
"defaultValue": 0
},
{
"id": "afca201a-5213-43fe-bfec-cae6ce7509d2",
"name": "error2",
"displayName": "Error 2",
"displayNameEvent": "Error 2 changed",
"type": "int",
"defaultValue": 0
},
{
"id": "c3fca233-95b9-4948-88c6-4c0f13cf53b1",
"name": "model",
@ -83,7 +67,6 @@
"type": "QString",
"defaultValue": ""
},
{
"id": "83ed0774-2a91-434d-b03c-d920d02f2981",
"name": "power",
@ -103,6 +86,16 @@
"type": "bool",
"defaultValue": false
},
{
"id": "6713b2e7-41b3-4596-a304-3065726bdbe4",
"name": "phaseCount",
"displayName": "Number of connected phases",
"displayNameEvent": "Number of connected phases changed",
"type": "uint",
"minValue": 1,
"maxValue": 3,
"defaultValue": 1
},
{
"id": "539e5602-6dd9-465d-9705-3bb59bcf8982",
"name": "activity",
@ -128,14 +121,12 @@
"defaultValue": false
},
{
"id": "a29c1748-fe97-4830-a56e-e1cc4e618385",
"name": "current",
"displayName": "Current",
"displayNameEvent": "Current changed",
"type": "double",
"unit": "Ampere",
"defaultValue": 0.00,
"suggestLogging": true
"id": "c9785626-2501-478d-8c18-c42ad5d9a269",
"name": "charging",
"displayName": "Charging",
"displayNameEvent": "Charging changed",
"type": "bool",
"defaultValue": false
},
{
"id": "593656f0-babf-4308-8767-68f34e10fb15",
@ -143,25 +134,11 @@
"displayName": "Maximal charging current",
"displayNameEvent": "Maximal charging current changed",
"displayNameAction": "Set maximal charging current",
"type": "double",
"type": "uint",
"unit": "Ampere",
"defaultValue": 6.0,
"minValue": 6.0,
"maxValue": 32.0,
"writable": true,
"suggestLogging": true
},
{
"id": "da0cfb97-0b27-4d8f-bdf7-45b1ca727038",
"name": "maxChargingCurrentGeneral",
"displayName": "Maximal general charging current",
"displayNameEvent": "Maximal general charging current changed",
"displayNameAction": "Set maximal general charging current",
"type": "double",
"unit": "Ampere",
"defaultValue": 6.0,
"minValue": 6.0,
"maxValue": 32.0,
"defaultValue": 6,
"minValue": 6,
"maxValue": 32,
"writable": true,
"suggestLogging": true
},
@ -174,41 +151,50 @@
"unit": "Percentage",
"defaultValue": 100,
"minValue": 0,
"maxValue": 100,
"maxValue": 100
},
{
"id": "33e2ed95-f01e-44db-8156-34d124a8ecc8",
"name": "maxChargingCurrentHardware",
"displayName": "Maximal hardware charging current",
"displayNameEvent": "Maximal hardware charging current changed",
"type": "uint",
"unit": "Ampere",
"defaultValue": 32,
"suggestLogging": true
},
{
"id": "4a2d75d8-a3a0-4b40-9ca7-e8b6f11d0ef9",
"name": "voltagePhase1",
"displayName": "Voltage phase 1",
"displayNameEvent": "Voltage phase 1 changed",
"name": "voltagePhaseA",
"displayName": "Voltage phase A",
"displayNameEvent": "Voltage phase A changed",
"type": "int",
"unit": "Volt",
"defaultValue": 0
},
{
"id": "c8344ca5-21ac-4cd1-8f4b-e5ed202c5862",
"name": "voltagePhase2",
"displayName": "Voltage phase 2",
"displayNameEvent": "Voltage phase 2 changed",
"name": "voltagePhaseB",
"displayName": "Voltage phase B",
"displayNameEvent": "Voltage phase B changed",
"type": "int",
"unit": "Volt",
"defaultValue": 0
},
{
"id": "5f01e86c-0943-4849-a01a-db441916ebd5",
"name": "voltagePhase3",
"displayName": "Voltage phase 3",
"displayNameEvent": "Voltage phase 3 changed",
"name": "voltagePhaseC",
"displayName": "Voltage phase C",
"displayNameEvent": "Voltage phase C changed",
"type": "int",
"unit": "Volt",
"defaultValue": 0
},
{
"id": "31ec17b0-11e3-4332-92b0-fea821cf024f",
"name": "currentPhase1",
"displayName": "Current phase 1",
"displayNameEvent": "Current phase 1 changed",
"name": "currentPhaseA",
"displayName": "Current phase A",
"displayNameEvent": "Current phase A changed",
"type": "double",
"unit": "Ampere",
"defaultValue": 0.00,
@ -216,9 +202,9 @@
},
{
"id": "cdc7e10a-0d0a-4e93-ad2c-d34ffca45c97",
"name": "currentPhase2",
"displayName": "Current phase 2",
"displayNameEvent": "Current phase 2 changed",
"name": "currentPhaseB",
"displayName": "Current phase B",
"displayNameEvent": "Current phase B changed",
"type": "double",
"unit": "Ampere",
"defaultValue": 0.00,
@ -226,9 +212,9 @@
},
{
"id": "da838dc8-85f0-4e55-b4b5-cb93a43b373d",
"name": "currentPhase3",
"displayName": "Current phase 3",
"displayNameEvent": "Current phase 3 changed",
"name": "currentPhaseC",
"displayName": "Current phase C",
"displayNameEvent": "Current phase C changed",
"type": "double",
"unit": "Ampere",
"defaultValue": 0.00,
@ -317,6 +303,22 @@
"unit": "Minutes",
"defaultValue": 0
},
{
"id": "b44bc948-1234-4f87-9a22-bfb6de09df4d",
"name": "error1",
"displayName": "Error 1",
"displayNameEvent": "Error 1 changed",
"type": "int",
"defaultValue": 0
},
{
"id": "afca201a-5213-43fe-bfec-cae6ce7509d2",
"name": "error2",
"displayName": "Error 2",
"displayNameEvent": "Error 2 changed",
"type": "int",
"defaultValue": 0
},
{
"id": "f1758c5c-2c02-41cb-93ec-b778a3c78d28",
"name": "failsafeMode",