Merge PR #764: EVerest: Add phase switching

This commit is contained in:
jenkins 2025-03-30 20:36:45 +02:00
commit 5189756c41
4 changed files with 47 additions and 15 deletions

View File

@ -133,7 +133,16 @@ void Everest::setMaxChargingCurrent(double current)
QByteArray payload = QByteArray::number(current);
m_client->publish(topic, payload);
}
void Everest::setMaxChargingCurrentAndPhaseCount(uint phasesCount, double current)
{
QString topic = m_topicPrefix + "/cmd/set_limit_amps_phases";
QVariantMap data;
data.insert("amps", current);
data.insert("phases", phasesCount);
m_client->publish(topic, QJsonDocument::fromVariant(data).toJson());
}
void Everest::onConnected()
@ -207,16 +216,16 @@ void Everest::onPublishReceived(const QString &topic, const QByteArray &payload,
m_thing->setStateMaxValue(everestMaxChargingCurrentStateTypeId, maxCurrent);
m_thing->setStateMinValue(everestMaxChargingCurrentStateTypeId, minCurrent == 0 ? 6 : minCurrent);
// FIXME: once we have a method for phase switching, we can re-enable the featre here
// bool phaseSwitchingAvailable = dataMap.value("supports_changing_phases_during_charging", false).toBool();
// if (!phaseSwitchingAvailable) {
// // Only option left is set the desired phase count to 3, force that value
// m_thing->setStatePossibleValues(everestDesiredPhaseCountStateTypeId, { 3 });
// m_thing->setStateValue(everestDesiredPhaseCountStateTypeId, 3);
// } else {
// m_thing->setStatePossibleValues(everestDesiredPhaseCountStateTypeId, { 1, 3 });
// }
bool phaseSwitchingAvailable = dataMap.value("supports_changing_phases_during_charging", false).toBool();
if (!phaseSwitchingAvailable) {
// Only option left is set the desired phase count to 3, force that value
m_thing->setStatePossibleValues(everestDesiredPhaseCountStateTypeId, { 3 });
m_thing->setStateValue(everestDesiredPhaseCountStateTypeId, 3);
m_thing->setStateValue(everestPhaseCountStateTypeId, 3);
} else {
m_thing->setStatePossibleValues(everestDesiredPhaseCountStateTypeId, { 1, 3 });
m_thing->setStateValue(everestPhaseCountStateTypeId, m_thing->stateValue(everestDesiredPhaseCountStateTypeId));
}
} else if (topic.endsWith("limits")) {
/*
@ -227,7 +236,7 @@ void Everest::onPublishReceived(const QString &topic, const QByteArray &payload,
}
*/
QVariantMap dataMap = jsonDoc.toVariant().toMap();
m_thing->setStateValue(everestPhaseCountStateTypeId, dataMap.value("nr_of_phases_available").toUInt());
//m_thing->setStateValue(everestPhaseCountStateTypeId, dataMap.value("nr_of_phases_available").toUInt());
double maxCurrent = dataMap.value("max_current").toDouble();
if (maxCurrent >= 6) {
// FIXME: make it a double again once supported from the interface
@ -312,7 +321,6 @@ void Everest::onPublishReceived(const QString &topic, const QByteArray &payload,
QVariantMap dataMap = jsonDoc.toVariant().toMap();
m_thing->setStateValue(everestTemperatureStateTypeId, dataMap.value("temperature").toDouble());
m_thing->setStateValue(everestFanSpeedStateTypeId, dataMap.value("fan_rpm").toDouble());
}
}

View File

@ -69,9 +69,12 @@ public:
void deinitialize();
void enableCharging(bool enable);
// Use only without phase switching
void setMaxChargingCurrent(double current);
signals:
// Use also for setting the charging current if phase switching is available
void setMaxChargingCurrentAndPhaseCount(uint phasesCount, double current);
private slots:
void onConnected();

View File

@ -264,11 +264,20 @@ void IntegrationPluginEverest::executeAction(ThingActionInfo *info)
thing->setStateValue(everestPowerStateTypeId, power);
info->finish(Thing::ThingErrorNoError);
} else if (info->action().actionTypeId() == everestMaxChargingCurrentActionTypeId) {
// Note: once we support phase switching, we cannot use the
uint phaseCount = thing->stateValue(everestDesiredPhaseCountStateTypeId).toUInt();
double current = info->action().paramValue(everestMaxChargingCurrentActionMaxChargingCurrentParamTypeId).toDouble();
qCDebug(dcEverest()) << "Setting max charging current to" << current << thing;
everest->setMaxChargingCurrent(current);
qCDebug(dcEverest()).nospace() << "Setting max charging current to " << current << "A (Phases: " << phaseCount << ") " << thing;
everest->setMaxChargingCurrentAndPhaseCount(phaseCount, current);
thing->setStateValue(everestMaxChargingCurrentStateTypeId, current);
info->finish(Thing::ThingErrorNoError);
} else if (info->action().actionTypeId() == everestDesiredPhaseCountActionTypeId) {
uint phaseCount = info->action().paramValue(everestDesiredPhaseCountActionDesiredPhaseCountParamTypeId).toUInt();
double current = thing->stateValue(everestMaxChargingCurrentStateTypeId).toDouble();
qCDebug(dcEverest()).nospace() << "Setting desired phase count to " << phaseCount << " (" << current << "A) " << thing;
everest->setMaxChargingCurrentAndPhaseCount(phaseCount, current);
thing->setStateValue(everestDesiredPhaseCountStateTypeId, phaseCount);
info->finish(Thing::ThingErrorNoError);
}
return;

View File

@ -92,6 +92,18 @@
"maxValue": 3,
"defaultValue": 1
},
{
"id": "1dc5fbff-354b-4a68-aae3-95150b257faa",
"name": "desiredPhaseCount",
"displayName": "Desired phase count",
"displayNameAction": "Set desired phase count",
"type": "uint",
"minValue": 1,
"maxValue": 3,
"possibleValues": [1, 3],
"writable": true,
"defaultValue": 3
},
{
"id": "2104641b-1004-4637-8eca-108f53dcb402",
"name": "connected",