diff --git a/sma/README.md b/sma/README.md index b4b47cdb..63ffbd03 100644 --- a/sma/README.md +++ b/sma/README.md @@ -11,5 +11,4 @@ nymea plug-in for SMA solar equipment. * The package "nymea-plugin-sma" must be installed. ## More - https://www.sma.de/en/ diff --git a/sma/integrationpluginsma.cpp b/sma/integrationpluginsma.cpp index ddc7cfc9..4d679db9 100644 --- a/sma/integrationpluginsma.cpp +++ b/sma/integrationpluginsma.cpp @@ -121,7 +121,7 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info) info->finish(Thing::ThingErrorNoError); } else { //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()) info->finish(Thing::ThingErrorNoError); @@ -148,6 +148,7 @@ void IntegrationPluginSma::postSetupThing(Thing *thing) return; QString key = thing->paramValue(inverterThingIdParamTypeId).toString(); sunnyWebBox->getParameters(QStringList() << key); + sunnyWebBox->getProcessData(QStringList() << key); } } @@ -190,8 +191,14 @@ void IntegrationPluginSma::thingRemoved(Thing *thing) void IntegrationPluginSma::onRefreshTimer() { - Q_FOREACH(SunnyWebBox *sunnyWebBox, m_sunnyWebBoxes) { + Q_FOREACH(Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) { + SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(thing); 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) return; 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) @@ -216,8 +228,8 @@ void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, Sun return; thing->setStateValue(sunnyWebBoxCurrentPowerStateTypeId, overview.power); - thing->setStateValue(sunnyWebBoxDayEnergyStateTypeId, overview.dailyYield); - thing->setStateValue(sunnyWebBoxTotalEnergyStateTypeId, overview.totalYield); + thing->setStateValue(sunnyWebBoxDayEnergyProducedStateTypeId, overview.dailyYield); + thing->setStateValue(sunnyWebBoxTotalEnergyProducedStateTypeId, overview.totalYield); thing->setStateValue(sunnyWebBoxModeStateTypeId, overview.status); if (!overview.error.isEmpty()){ 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())) { if (childThing->paramValue(inverterThingIdParamTypeId).toString() == deviceKey) { - if (channels.contains("E-Total")) { - //TODO set total energy + Q_FOREACH(QString channel, channels.keys()) { + qCDebug(dcSma()) << " - Channel received" << channel << channels.value(channel); + //TODO parse data } break; } @@ -292,8 +305,3 @@ void IntegrationPluginSma::onParameterChannelsReceived(const QString &messageId, qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels; } - -void IntegrationPluginSma::getData(Thing *thing) -{ - Q_UNUSED(thing) -} diff --git a/sma/integrationpluginsma.h b/sma/integrationpluginsma.h index 8e572c60..5fef831c 100644 --- a/sma/integrationpluginsma.h +++ b/sma/integrationpluginsma.h @@ -72,8 +72,6 @@ private: QHash m_asyncSetup; QHash m_asyncActions; SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr; - - void getData(Thing *thing); }; #endif // INTEGRATIONPLUGINSMA_H diff --git a/sma/integrationpluginsma.json b/sma/integrationpluginsma.json index bb40003a..babbc720 100644 --- a/sma/integrationpluginsma.json +++ b/sma/integrationpluginsma.json @@ -13,7 +13,7 @@ "name": "sunnyWebBox", "displayName": "Sunny WebBox", "createMethods": ["user", "discovery"], - "interfaces": ["gateway"], + "interfaces": ["extendedsmartmeterproducer", "gateway"], "paramTypes": [ { "id": "864d4162-e3ce-48b8-b8ac-c1b971b52d42", @@ -52,18 +52,18 @@ }, { "id": "16f34c5c-8dbb-4dcc-9faa-4b782d57226c", - "name": "dayEnergy", - "displayName": "Day energy", - "displayNameEvent": "Day energy changed", + "name": "dayEnergyProduced", + "displayName": "Day energy produced", + "displayNameEvent": "Day energy produced changed", "type": "double", "unit": "KiloWattHour", "defaultValue": 0 }, { "id": "0bb4e227-7e38-49ca-9b32-ce4621c9305b", - "name": "totalEnergy", - "displayName": "Total energy", - "displayNameEvent": "Total energy changed", + "name": "totalEnergyProduced", + "displayName": "Total energy produced", + "displayNameEvent": "Total energy produced changed", "type": "double", "unit": "KiloWattHour", "defaultValue": 0 diff --git a/sma/sunnywebbox.cpp b/sma/sunnywebbox.cpp index 8323b8e0..7d455803 100644 --- a/sma/sunnywebbox.cpp +++ b/sma/sunnywebbox.cpp @@ -188,6 +188,7 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT } else if (messageType == "GetProcessData") { QList devices; QVariantList devicesList = result.value("devices").toList(); + qCDebug(dcSma()) << "SunnyWebBox: GetProcessData response received"; Q_FOREACH(QVariant value, devicesList) { QString key = value.toMap().value("key").toString();