Merge PR #653: go-e: Add possibility to control charging phases
commit
ee990d7e48
|
|
@ -387,6 +387,45 @@ void IntegrationPluginGoECharger::executeAction(ThingActionInfo *info)
|
|||
}
|
||||
});
|
||||
return;
|
||||
} else if (action.actionTypeId() == goeHomeDesiredPhaseCountActionTypeId) {
|
||||
uint desiredPhases = action.paramValue(goeHomeDesiredPhaseCountActionDesiredPhaseCountParamTypeId).toUInt();
|
||||
QString value = desiredPhases == 1 ? "1" : "2"; // 1: 1-Phase, 2: 3-Phases (0: Auto)
|
||||
qCDebug(dcGoECharger()) << "Setting phaseSwitchMode to" << value;
|
||||
// Warning: using QUrlQuery not always works here due to standard mixing from go-e:
|
||||
// The url query has to be JSON encoded, i.e. <url>/set?fna="mein charger"
|
||||
QUrlQuery configuration;
|
||||
configuration.addQueryItem("psm", value);
|
||||
QNetworkRequest request = buildConfigurationRequestV2(address, configuration);
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||
connect(info, &ThingActionInfo::aborted, reply, &QNetworkReply::abort);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, info, [=](){
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcGoECharger()) << "Execute action failed for" << thing->name() << "HTTP error:" << reply->errorString() << reply->readAll() << "Request was:" << request.url().toString();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("The wallbox does not seem to be reachable."));
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray data = reply->readAll();
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcGoECharger()) << "Execute action failed for" << thing->name() << "Failed to parse data" << qUtf8Printable(data) << error.errorString() << "Request was:" << request.url().toString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure, QT_TR_NOOP("The wallbox returned invalid data."));
|
||||
return;
|
||||
}
|
||||
|
||||
QVariantMap responseCode = jsonDoc.toVariant().toMap();
|
||||
if (responseCode.value("psm", false).toBool()) {
|
||||
qCDebug(dcGoECharger()) << "Execute action finished successfully. phaseSwitchMode" << value << "desired phases:" << desiredPhases;
|
||||
thing->setStateValue(goeHomeDesiredPhaseCountStateTypeId, desiredPhases);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
} else {
|
||||
qCWarning(dcGoECharger()) << "Action finished with error:" << responseCode.value("psm").toString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure);
|
||||
}
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
info->finish(Thing::ThingErrorActionTypeNotFound);
|
||||
}
|
||||
|
|
@ -572,6 +611,7 @@ void IntegrationPluginGoECharger::updateV1(Thing *thing, const QVariantMap &stat
|
|||
// FIXME: check if we can use amx since it is better for pv charging, not all version seen implement this
|
||||
thing->setStateValue(goeHomeMaxChargingCurrentStateTypeId, statusMap.value("amp").toUInt());
|
||||
thing->setStateValue(goeHomeAdapterConnectedStateTypeId, (statusMap.value("adi").toUInt() == 0 ? false : true));
|
||||
thing->setStateValue(goeHomeDesiredPhaseCountStateTypeId, statusMap.value("psm").toUInt() == 1 ? 1 : 3);
|
||||
|
||||
uint amaLimit = statusMap.value("ama").toUInt();
|
||||
uint cableLimit = statusMap.value("cbl").toUInt();
|
||||
|
|
|
|||
|
|
@ -321,6 +321,18 @@
|
|||
"maxValue": 3,
|
||||
"defaultValue": 1
|
||||
},
|
||||
{
|
||||
"id": "db0af9a7-08fd-4224-b071-c89e11ae8c47",
|
||||
"name": "desiredPhaseCount",
|
||||
"displayName": "Desired number of charging phases",
|
||||
"displayNameAction": "Set desired number of charging phases",
|
||||
"type": "uint",
|
||||
"possibleValues": [1, 3],
|
||||
"defaultValue": 1,
|
||||
"minValue": 1,
|
||||
"maxValue": 3,
|
||||
"writable": true
|
||||
},
|
||||
{
|
||||
"id": "2bf1ebf1-0d8c-4209-ad35-4114d9861832",
|
||||
"name": "temperatureSensor1",
|
||||
|
|
|
|||
Loading…
Reference in New Issue