Merge PR #40: Update wallbox interface states

pull/48/head
Jenkins nymea 2021-12-13 00:48:11 +01:00
commit 595d490e30
4 changed files with 64 additions and 7 deletions

View File

@ -82,7 +82,7 @@
"displayName": "Charging current",
"displayNameEvent": "Charging current changed",
"displayNameAction": "Set charging current",
"type": "double",
"type": "uint",
"unit": "Ampere",
"minValue": 6,
"maxValue": 80,

View File

@ -209,7 +209,7 @@ void IntegrationPluginWebasto::executeAction(ThingActionInfo *info)
thing->setStateValue(liveWallboxPowerActionTypeId, enabled);
int ampere = 0;
if (enabled) {
ampere = thing->stateValue(liveWallboxMaxChargingCurrentStateTypeId).toInt();
ampere = thing->stateValue(liveWallboxMaxChargingCurrentStateTypeId).toUInt();
}
QUuid requestId = connection->setChargeCurrent(ampere);
if (requestId.isNull()) {
@ -218,7 +218,7 @@ void IntegrationPluginWebasto::executeAction(ThingActionInfo *info)
m_asyncActions.insert(requestId, info);
}
} else if (action.actionTypeId() == liveWallboxMaxChargingCurrentActionTypeId) {
int ampere = action.paramValue(liveWallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toInt();
int ampere = action.paramValue(liveWallboxMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toUInt();
thing->setStateValue(liveWallboxMaxChargingCurrentStateTypeId, ampere);
QUuid requestId = connection->setChargeCurrent(ampere);
if (requestId.isNull()) {
@ -266,6 +266,27 @@ void IntegrationPluginWebasto::update(Webasto *webasto)
webasto->getRegister(Webasto::TqUserId, 10);
}
void IntegrationPluginWebasto::evaluatePhaseCount(Thing *thing)
{
uint amperePhase1 = thing->stateValue(liveWallboxCurrentPhase1StateTypeId).toUInt();
uint amperePhase2 = thing->stateValue(liveWallboxCurrentPhase2StateTypeId).toUInt();
uint amperePhase3 = thing->stateValue(liveWallboxCurrentPhase3StateTypeId).toUInt();
// Check how many phases are actually charging, and update the phase count only if something happens on the phases (current or power)
if (!(amperePhase1 == 0 && amperePhase2 == 0 && amperePhase3 == 0)) {
uint phaseCount = 0;
if (amperePhase1 != 0)
phaseCount += 1;
if (amperePhase2 != 0)
phaseCount += 1;
if (amperePhase3 != 0)
phaseCount += 1;
thing->setStateValue(liveWallboxPhaseCountStateTypeId, phaseCount);
}
}
void IntegrationPluginWebasto::onConnectionChanged(bool connected)
{
Webasto *connection = static_cast<Webasto *>(sender());
@ -339,6 +360,8 @@ void IntegrationPluginWebasto::onReceivedRegister(Webasto::TqModbusRegister modb
thing->setStateValue(liveWallboxChargePointStateStateTypeId, "User not authorized (car attached)");
break;
}
thing->setStateValue(liveWallboxChargingStateTypeId, Webasto::ChargePointState(data[0]) == Webasto::ChargePointStateCharging);
break;
case Webasto::TqChargeState:
qCDebug(dcWebasto()) << " - Charge state:" << data[0];
@ -351,15 +374,19 @@ void IntegrationPluginWebasto::onReceivedRegister(Webasto::TqModbusRegister modb
switch (Webasto::CableState(data[0])) {
case Webasto::CableStateNoCableAttached:
thing->setStateValue(liveWallboxCableStateStateTypeId, "No cable attached");
thing->setStateValue(liveWallboxPluggedInStateTypeId, false);
break;
case Webasto::CableStateCableAttachedNoCarAttached:
thing->setStateValue(liveWallboxCableStateStateTypeId, "Cable attached but no car attached)");
thing->setStateValue(liveWallboxPluggedInStateTypeId, false);
break;
case Webasto::CableStateCableAttachedCarAttached:
thing->setStateValue(liveWallboxCableStateStateTypeId, "Cable attached and car attached");
thing->setStateValue(liveWallboxPluggedInStateTypeId, true);
break;
case Webasto::CableStateCableAttachedCarAttachedLockActive:
thing->setStateValue(liveWallboxCableStateStateTypeId, "Cable attached, car attached and lock active");
thing->setStateValue(liveWallboxPluggedInStateTypeId, true);
break;
}
break;
@ -370,14 +397,17 @@ void IntegrationPluginWebasto::onReceivedRegister(Webasto::TqModbusRegister modb
case Webasto::TqCurrentL1:
qCDebug(dcWebasto()) << " - Current L1:" << data[0];
thing->setStateValue(liveWallboxCurrentPhase1StateTypeId, data[0]);
evaluatePhaseCount(thing);
break;
case Webasto::TqCurrentL2:
qCDebug(dcWebasto()) << " - Current L2:" << data[0];
thing->setStateValue(liveWallboxCurrentPhase2StateTypeId, data[0]);
evaluatePhaseCount(thing);
break;
case Webasto::TqCurrentL3:
qCDebug(dcWebasto()) << " - Current L3:" << data[0];
thing->setStateValue(liveWallboxCurrentPhase3StateTypeId, data[0]);
evaluatePhaseCount(thing);
break;
case Webasto::TqActivePower: {
if (data.count() < 2)

View File

@ -62,6 +62,7 @@ private:
QHash<QUuid, ThingActionInfo *> m_asyncActions;
void update(Webasto *webasto);
void evaluatePhaseCount(Thing *thing);
private slots:
void onConnectionChanged(bool connected);

View File

@ -91,13 +91,39 @@
"displayName": "Charging current",
"displayNameAction": "Set charging current",
"displayNameEvent": "Charging current changed",
"type": "double",
"type": "uint",
"unit": "Ampere",
"minValue": 6.00,
"maxValue": 80.00,
"defaultValue": 6.00,
"minValue": 6,
"maxValue": 80,
"defaultValue": 6,
"writable": true
},
{
"id": "0e15e78e-a233-4026-a0fd-f65edc824f1e",
"name": "pluggedIn",
"displayName": "Car plugged in",
"displayNameEvent": "Car plugged in changed",
"type": "bool",
"defaultValue": false
},
{
"id": "8f35404d-8237-4ff8-8774-9ad10ceee5c3",
"name": "charging",
"displayName": "Charging",
"displayNameEvent": "Charging changed",
"type": "bool",
"defaultValue": false
},
{
"id": "179e6136-2ac1-4247-b457-f804e2212293",
"name": "phaseCount",
"displayName": "Number of connected phases",
"displayNameEvent": "Number of connected phases changed",
"type": "uint",
"minValue": 1,
"maxValue": 3,
"defaultValue": 1
},
{
"id": "2027fbb6-c9d2-4a75-bdd0-a3ad3785cdc6",
"name": "currentPhase1",