added get process data call

This commit is contained in:
Boernsman 2021-02-26 20:29:30 +01:00 committed by Simon Stürz
parent d777f9c7f4
commit ef5c791658
5 changed files with 27 additions and 21 deletions

View File

@ -11,5 +11,4 @@ nymea plug-in for SMA solar equipment.
* The package "nymea-plugin-sma" must be installed. * The package "nymea-plugin-sma" must be installed.
## More ## More
https://www.sma.de/en/ https://www.sma.de/en/

View File

@ -121,7 +121,7 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
} else { } else {
//wait for the parent to finish the setup process //wait for the parent to finish the setup process
connect(parentThing, &Thing::setupStatusChanged, info, [this, info, parentThing] { connect(parentThing, &Thing::setupStatusChanged, info, [info, parentThing] {
if (parentThing->setupComplete()) if (parentThing->setupComplete())
info->finish(Thing::ThingErrorNoError); info->finish(Thing::ThingErrorNoError);
@ -148,6 +148,7 @@ void IntegrationPluginSma::postSetupThing(Thing *thing)
return; return;
QString key = thing->paramValue(inverterThingIdParamTypeId).toString(); QString key = thing->paramValue(inverterThingIdParamTypeId).toString();
sunnyWebBox->getParameters(QStringList() << key); sunnyWebBox->getParameters(QStringList() << key);
sunnyWebBox->getProcessData(QStringList() << key);
} }
} }
@ -190,8 +191,14 @@ void IntegrationPluginSma::thingRemoved(Thing *thing)
void IntegrationPluginSma::onRefreshTimer() void IntegrationPluginSma::onRefreshTimer()
{ {
Q_FOREACH(SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes) { Q_FOREACH(Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) {
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(thing);
sunnyWebBox->getPlantOverview(); sunnyWebBox->getPlantOverview();
Q_FOREACH(Thing *child, myThings().filterByParentId(thing->id())) {
QString key = child->paramValue(inverterThingIdParamTypeId).toString();
sunnyWebBox->getProcessData(QStringList() << key);
}
} }
} }
@ -201,6 +208,11 @@ void IntegrationPluginSma::onConnectedChanged(bool connected)
if (!thing) if (!thing)
return; return;
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, connected); thing->setStateValue(sunnyWebBoxConnectedStateTypeId, connected);
if (!connected) {
Q_FOREACH(Thing *child, myThings().filterByParentId(thing->id())) {
child->setStateValue(inverterConnectedStateTypeId, false);
}
}
} }
void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview) void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview)
@ -216,8 +228,8 @@ void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, Sun
return; return;
thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, overview.power); thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, overview.power);
thing->setStateValue(sunnyWebBoxDayEnergyStateTypeId, overview.dailyYield); thing->setStateValue(sunnyWebBoxDayEnergyProducedStateTypeId, overview.dailyYield);
thing->setStateValue(sunnyWebBoxTotalEnergyStateTypeId, overview.totalYield); thing->setStateValue(sunnyWebBoxTotalEnergyProducedStateTypeId, overview.totalYield);
thing->setStateValue(sunnyWebBoxModeStateTypeId, overview.status); thing->setStateValue(sunnyWebBoxModeStateTypeId, overview.status);
if (!overview.error.isEmpty()){ if (!overview.error.isEmpty()){
qCDebug(dcSma()) << "Received error" << overview.error; qCDebug(dcSma()) << "Received error" << overview.error;
@ -274,8 +286,9 @@ void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const
Q_FOREACH(Thing *childThing, myThings().filterByParentId(thing->id())) { Q_FOREACH(Thing *childThing, myThings().filterByParentId(thing->id())) {
if (childThing->paramValue(inverterThingIdParamTypeId).toString() == deviceKey) { if (childThing->paramValue(inverterThingIdParamTypeId).toString() == deviceKey) {
if (channels.contains("E-Total")) { Q_FOREACH(QString channel, channels.keys()) {
//TODO set total energy qCDebug(dcSma()) << " - Channel received" << channel << channels.value(channel);
//TODO parse data
} }
break; break;
} }
@ -292,8 +305,3 @@ void IntegrationPluginSma::onParameterChannelsReceived(const QString &messageId,
qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels; qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels;
} }
void IntegrationPluginSma::getData(Thing *thing)
{
Q_UNUSED(thing)
}

View File

@ -72,8 +72,6 @@ private:
QHash<QString, ThingSetupInfo *> m_asyncSetup; QHash<QString, ThingSetupInfo *> m_asyncSetup;
QHash<QString, ThingActionInfo *> m_asyncActions; QHash<QString, ThingActionInfo *> m_asyncActions;
SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr; SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr;
void getData(Thing *thing);
}; };
#endif // INTEGRATIONPLUGINSMA_H #endif // INTEGRATIONPLUGINSMA_H

View File

@ -13,7 +13,7 @@
"name": "sunnyWebBox", "name": "sunnyWebBox",
"displayName": "Sunny WebBox", "displayName": "Sunny WebBox",
"createMethods": ["user", "discovery"], "createMethods": ["user", "discovery"],
"interfaces": ["gateway"], "interfaces": ["extendedsmartmeterproducer", "gateway"],
"paramTypes": [ "paramTypes": [
{ {
"id": "864d4162-e3ce-48b8-b8ac-c1b971b52d42", "id": "864d4162-e3ce-48b8-b8ac-c1b971b52d42",
@ -52,18 +52,18 @@
}, },
{ {
"id": "16f34c5c-8dbb-4dcc-9faa-4b782d57226c", "id": "16f34c5c-8dbb-4dcc-9faa-4b782d57226c",
"name": "dayEnergy", "name": "dayEnergyProduced",
"displayName": "Day energy", "displayName": "Day energy produced",
"displayNameEvent": "Day energy changed", "displayNameEvent": "Day energy produced changed",
"type": "double", "type": "double",
"unit": "KiloWattHour", "unit": "KiloWattHour",
"defaultValue": 0 "defaultValue": 0
}, },
{ {
"id": "0bb4e227-7e38-49ca-9b32-ce4621c9305b", "id": "0bb4e227-7e38-49ca-9b32-ce4621c9305b",
"name": "totalEnergy", "name": "totalEnergyProduced",
"displayName": "Total energy", "displayName": "Total energy produced",
"displayNameEvent": "Total energy changed", "displayNameEvent": "Total energy produced changed",
"type": "double", "type": "double",
"unit": "KiloWattHour", "unit": "KiloWattHour",
"defaultValue": 0 "defaultValue": 0

View File

@ -188,6 +188,7 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT
} else if (messageType == "GetProcessData") { } else if (messageType == "GetProcessData") {
QList<Device> devices; QList<Device> devices;
QVariantList devicesList = result.value("devices").toList(); QVariantList devicesList = result.value("devices").toList();
qCDebug(dcSma()) << "SunnyWebBox: GetProcessData response received";
Q_FOREACH(QVariant value, devicesList) { Q_FOREACH(QVariant value, devicesList) {
QString key = value.toMap().value("key").toString(); QString key = value.toMap().value("key").toString();