diff --git a/sma/integrationpluginsma.cpp b/sma/integrationpluginsma.cpp index fb5a9440..15a4e048 100644 --- a/sma/integrationpluginsma.cpp +++ b/sma/integrationpluginsma.cpp @@ -178,11 +178,42 @@ void IntegrationPluginSma::onDevicesReceived(int messageId, QList &channels) +{ + Thing *thing = m_sunnyWebBoxes.key(static_cast(sender())); + if (!thing) + return; + + qCDebug(dcSma()) << "Process data received" << deviceKey; + + Q_FOREACH(Thing *childThing, myThings().filterByParentId(thing->id())) { + if (childThing->paramValue(inverterThingIdParamTypeId).toString() == deviceKey) { + if (channels.contains("E-Total")) { + //TODO set total energy + } + break; + } + } +} + +void IntegrationPluginSma::onParameterChannelsReceived(int messageId, const QString &deviceKey, QStringList parameterChannels) +{ + Q_UNUSED(messageId) + + Thing *thing = m_sunnyWebBoxes.key(static_cast(sender())); + if (!thing) + return; + + qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels; +} + SunnyWebBox * IntegrationPluginSma::createSunnyWebBoxConnection(Thing *thing) { SunnyWebBox *sunnyWebBox = new SunnyWebBox(m_sunnyWebBoxCommunication, QHostAddress(thing->paramValue(sunnyWebBoxThingHostParamTypeId).toString()), this); m_sunnyWebBoxes.insert(thing, sunnyWebBox); connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived); + connect(sunnyWebBox, &SunnyWebBox::parameterChannelsReceived, this, &IntegrationPluginSma::onParameterChannelsReceived); + //connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived); return sunnyWebBox; } diff --git a/sma/integrationpluginsma.h b/sma/integrationpluginsma.h index 90f44134..e968dc17 100644 --- a/sma/integrationpluginsma.h +++ b/sma/integrationpluginsma.h @@ -60,6 +60,8 @@ private slots: void onPlantOverviewReceived(int messageId, SunnyWebBox::Overview overview); void onDevicesReceived(int messageId, QList devices); + void onProcessDataReceived(int messageId, const QString &deviceKey, const QHash &channels); + void onParameterChannelsReceived(int messageId, const QString &deviceKey, QStringList parameterChannels); private: PluginTimer *m_refreshTimer = nullptr; diff --git a/sma/sunnywebbox.cpp b/sma/sunnywebbox.cpp index 61feb1ac..90738b1d 100644 --- a/sma/sunnywebbox.cpp +++ b/sma/sunnywebbox.cpp @@ -109,6 +109,11 @@ void SunnyWebBox::onMessageReceived(const QHostAddress &address, int messageId, } else if (messageType == "GetProcessDataChannels") { } else if (messageType == "GetProcessData") { } else if (messageType == "GetParameterChannels") { + Q_FOREACH(QString deviceKey, result.keys()) { + QStringList parameterChannels = result.value(deviceKey).toStringList(); + if (!parameterChannels.isEmpty()) + emit parameterChannelsReceived(messageId, deviceKey, parameterChannels); + } } else if (messageType == "GetParameter") { } else if (messageType == "SetParameter") { } else { diff --git a/sma/sunnywebbox.h b/sma/sunnywebbox.h index f039e4c4..3b4cf367 100644 --- a/sma/sunnywebbox.h +++ b/sma/sunnywebbox.h @@ -57,6 +57,13 @@ public: QList childrens; }; + struct Channel { + QString meta; + QString name; + QVariant value; + QString unit; + }; + explicit SunnyWebBox(SunnyWebBoxCommunication *communication, const QHostAddress &hostAddress, QObject *parrent = 0); int getPlantOverview(); @@ -83,6 +90,8 @@ signals: void plantOverviewReceived(int messageId, Overview overview); void devicesReceived(int messageId, QList devices); + void processDataReceived(int messageId, const QString &deviceKey, const QHash &channels); + void parameterChannelsReceived(int messageId, const QString &deviceKey, QStringList parameterChannels); }; #endif // SUNNYWEBBOX_H