reduced feature set
This commit is contained in:
parent
1c7ed8a09b
commit
ab26a22d00
@ -104,30 +104,8 @@ void IntegrationPluginSma::setupThing(ThingSetupInfo *info)
|
|||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::connectedChanged, this, &IntegrationPluginSma::onConnectedChanged);
|
connect(sunnyWebBox, &SunnyWebBox::connectedChanged, this, &IntegrationPluginSma::onConnectedChanged);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived);
|
connect(sunnyWebBox, &SunnyWebBox::plantOverviewReceived, this, &IntegrationPluginSma::onPlantOverviewReceived);
|
||||||
connect(sunnyWebBox, &SunnyWebBox::devicesReceived, this, &IntegrationPluginSma::onDevicesReceived);
|
|
||||||
connect(sunnyWebBox, &SunnyWebBox::processDataReceived, this, &IntegrationPluginSma::onProcessDataReceived);
|
|
||||||
connect(sunnyWebBox, &SunnyWebBox::parameterChannelsReceived, this, &IntegrationPluginSma::onParameterChannelsReceived);
|
|
||||||
connect(sunnyWebBox, &SunnyWebBox::parametersReceived, this, &IntegrationPluginSma::onParametersReceived);
|
|
||||||
m_sunnyWebBoxes.insert(info->thing(), sunnyWebBox);
|
m_sunnyWebBoxes.insert(info->thing(), sunnyWebBox);
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
|
||||||
Thing *parentThing = myThings().findById(thing->parentId());
|
|
||||||
if (!parentThing) {
|
|
||||||
qCWarning(dcSma()) << "Could not find parentThing for thing " << thing->name();
|
|
||||||
return info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
|
||||||
}
|
|
||||||
if (parentThing->setupComplete()) {
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
} else {
|
|
||||||
//wait for the parent to finish the setup process
|
|
||||||
connect(parentThing, &Thing::setupStatusChanged, info, [info, parentThing] {
|
|
||||||
|
|
||||||
if (parentThing->setupComplete())
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||||
}
|
}
|
||||||
@ -142,37 +120,6 @@ void IntegrationPluginSma::postSetupThing(Thing *thing)
|
|||||||
return;
|
return;
|
||||||
sunnyWebBox->getDevices();
|
sunnyWebBox->getDevices();
|
||||||
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, true);
|
thing->setStateValue(sunnyWebBoxConnectedStateTypeId, true);
|
||||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
|
||||||
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(myThings().findById(thing->parentId()));
|
|
||||||
if (!sunnyWebBox)
|
|
||||||
return;
|
|
||||||
QString key = thing->paramValue(inverterThingIdParamTypeId).toString();
|
|
||||||
sunnyWebBox->getParameters(QStringList() << key);
|
|
||||||
sunnyWebBox->getProcessData(QStringList() << key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginSma::executeAction(ThingActionInfo *info)
|
|
||||||
{
|
|
||||||
Thing *thing = info->thing();
|
|
||||||
Action action = info->action();
|
|
||||||
|
|
||||||
if (thing->thingClassId() == sunnyWebBoxThingClassId) {
|
|
||||||
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(thing);
|
|
||||||
if (!sunnyWebBox)
|
|
||||||
return;
|
|
||||||
if (action.actionTypeId() == sunnyWebBoxSearchDevicesActionTypeId) {
|
|
||||||
QString requestId = sunnyWebBox->getDevices();
|
|
||||||
if (requestId.isEmpty()) {
|
|
||||||
return info->finish(Thing::ThingErrorHardwareNotAvailable);
|
|
||||||
}
|
|
||||||
m_asyncActions.insert(requestId, info);
|
|
||||||
connect(info, &ThingActionInfo::aborted, info, [requestId, this] {m_asyncActions.remove(requestId);});
|
|
||||||
} else {
|
|
||||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,11 +141,6 @@ void IntegrationPluginSma::onRefreshTimer()
|
|||||||
Q_FOREACH(Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) {
|
Q_FOREACH(Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) {
|
||||||
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(thing);
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,21 +150,13 @@ 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)
|
||||||
{
|
{
|
||||||
qCDebug(dcSma()) << "Plant overview received" << overview.status;
|
Q_UNUSED(messageId)
|
||||||
if (m_asyncSetup.contains(messageId)) {
|
|
||||||
ThingSetupInfo *info = m_asyncSetup.value(messageId);
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
qCDebug(dcSma()) << "Plant overview received" << overview.status;
|
||||||
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
||||||
if (!thing)
|
if (!thing)
|
||||||
return;
|
return;
|
||||||
@ -236,72 +170,3 @@ void IntegrationPluginSma::onPlantOverviewReceived(const QString &messageId, Sun
|
|||||||
thing->setStateValue(sunnyWebBoxErrorStateTypeId, overview.error);
|
thing->setStateValue(sunnyWebBoxErrorStateTypeId, overview.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void IntegrationPluginSma::onDevicesReceived(const QString &messageId, QList<SunnyWebBox::Device> devices)
|
|
||||||
{
|
|
||||||
qCDebug(dcSma()) << "Devices received, count:" << devices.count();
|
|
||||||
if (m_asyncActions.contains(messageId)) {
|
|
||||||
ThingActionInfo *info = m_asyncActions.value(messageId);
|
|
||||||
info->finish(Thing::ThingErrorNoError);
|
|
||||||
}
|
|
||||||
|
|
||||||
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
|
||||||
if (!thing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ThingDescriptors descriptors;
|
|
||||||
Q_FOREACH(SunnyWebBox::Device device, devices){
|
|
||||||
qCDebug(dcSma()) << " - Device received" << device.name << device.key;
|
|
||||||
if (myThings().findByParams(ParamList() << Param(inverterThingIdParamTypeId, device.key)))
|
|
||||||
continue;
|
|
||||||
ThingDescriptor descriptor(inverterThingClassId, device.name, device.key ,thing->id());
|
|
||||||
ParamList params;
|
|
||||||
params << Param(inverterThingIdParamTypeId, device.key);
|
|
||||||
descriptor.setParams(params);
|
|
||||||
descriptors.append(descriptor);
|
|
||||||
}
|
|
||||||
emit autoThingsAppeared(descriptors);
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginSma::onParametersReceived(const QString &messageId, const QString &deviceKey, const QList<SunnyWebBox::Parameter> ¶meters)
|
|
||||||
{
|
|
||||||
Q_UNUSED(messageId);
|
|
||||||
Thing *thing = myThings().findByParams(ParamList() << Param(inverterThingIdParamTypeId, deviceKey));
|
|
||||||
if (!thing)
|
|
||||||
return;
|
|
||||||
qCDebug(dcSma()) << "Parameters received";
|
|
||||||
Q_FOREACH(SunnyWebBox::Parameter parameter, parameters) {
|
|
||||||
qCDebug(dcSma()) << " - " << parameter.name << parameter.value << parameter.unit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginSma::onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels)
|
|
||||||
{
|
|
||||||
Q_UNUSED(messageId)
|
|
||||||
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
|
||||||
if (!thing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qCDebug(dcSma()) << "Process data received" << deviceKey;
|
|
||||||
|
|
||||||
Q_FOREACH(Thing *childThing, myThings().filterByParentId(thing->id())) {
|
|
||||||
if (childThing->paramValue(inverterThingIdParamTypeId).toString() == deviceKey) {
|
|
||||||
Q_FOREACH(QString channel, channels.keys()) {
|
|
||||||
qCDebug(dcSma()) << " - Channel received" << channel << channels.value(channel);
|
|
||||||
//TODO parse data
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void IntegrationPluginSma::onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels)
|
|
||||||
{
|
|
||||||
Q_UNUSED(messageId)
|
|
||||||
|
|
||||||
Thing *thing = m_sunnyWebBoxes.key(static_cast<SunnyWebBox *>(sender()));
|
|
||||||
if (!thing)
|
|
||||||
return;
|
|
||||||
|
|
||||||
qCDebug(dcSma()) << "Parameter channels received" << deviceKey << parameterChannels;
|
|
||||||
}
|
|
||||||
|
|||||||
@ -34,13 +34,9 @@
|
|||||||
#include "integrations/integrationplugin.h"
|
#include "integrations/integrationplugin.h"
|
||||||
#include "plugintimer.h"
|
#include "plugintimer.h"
|
||||||
#include "sunnywebbox.h"
|
#include "sunnywebbox.h"
|
||||||
#include "sunnywebboxcommunication.h"
|
|
||||||
#include "discovery.h"
|
#include "discovery.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QHostAddress>
|
|
||||||
#include <QUdpSocket>
|
|
||||||
|
|
||||||
|
|
||||||
class IntegrationPluginSma: public IntegrationPlugin {
|
class IntegrationPluginSma: public IntegrationPlugin {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -53,7 +49,6 @@ public:
|
|||||||
void discoverThings(ThingDiscoveryInfo *info) override;
|
void discoverThings(ThingDiscoveryInfo *info) override;
|
||||||
void setupThing(ThingSetupInfo *info) override;
|
void setupThing(ThingSetupInfo *info) override;
|
||||||
void postSetupThing(Thing *thing) override;
|
void postSetupThing(Thing *thing) override;
|
||||||
void executeAction(ThingActionInfo *info) override;
|
|
||||||
void thingRemoved(Thing *thing) override;
|
void thingRemoved(Thing *thing) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -61,17 +56,10 @@ private slots:
|
|||||||
|
|
||||||
void onConnectedChanged(bool connected);
|
void onConnectedChanged(bool connected);
|
||||||
void onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview);
|
void onPlantOverviewReceived(const QString &messageId, SunnyWebBox::Overview overview);
|
||||||
void onDevicesReceived(const QString &messageId, QList<SunnyWebBox::Device> devices);
|
|
||||||
void onParametersReceived(const QString &messageId, const QString &deviceKey, const QList<SunnyWebBox::Parameter> ¶meters);
|
|
||||||
void onProcessDataReceived(const QString &messageId, const QString &deviceKey, const QHash<QString, QVariant> &channels);
|
|
||||||
void onParameterChannelsReceived(const QString &messageId, const QString &deviceKey, QStringList parameterChannels);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginTimer *m_refreshTimer = nullptr;
|
PluginTimer *m_refreshTimer = nullptr;
|
||||||
QHash<Thing *, SunnyWebBox *> m_sunnyWebBoxes;
|
QHash<Thing *, SunnyWebBox *> m_sunnyWebBoxes;
|
||||||
QHash<QString, ThingSetupInfo *> m_asyncSetup;
|
|
||||||
QHash<QString, ThingActionInfo *> m_asyncActions;
|
|
||||||
SunnyWebBoxCommunication *m_sunnyWebBoxCommunication = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // INTEGRATIONPLUGINSMA_H
|
#endif // INTEGRATIONPLUGINSMA_H
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
"name": "sunnyWebBox",
|
"name": "sunnyWebBox",
|
||||||
"displayName": "Sunny WebBox",
|
"displayName": "Sunny WebBox",
|
||||||
"createMethods": ["user", "discovery"],
|
"createMethods": ["user", "discovery"],
|
||||||
"interfaces": ["extendedsmartmeterproducer", "gateway"],
|
"interfaces": ["extendedsmartmeterproducer"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
"id": "864d4162-e3ce-48b8-b8ac-c1b971b52d42",
|
"id": "864d4162-e3ce-48b8-b8ac-c1b971b52d42",
|
||||||
@ -84,76 +84,6 @@
|
|||||||
"type": "QString",
|
"type": "QString",
|
||||||
"defaultValue": "None"
|
"defaultValue": "None"
|
||||||
}
|
}
|
||||||
],
|
|
||||||
"actionTypes": [
|
|
||||||
{
|
|
||||||
"id": "15fc3dac-1868-4490-ba41-7c2f545926ad",
|
|
||||||
"name": "searchDevices",
|
|
||||||
"displayName": "Search new devices"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "9cb72321-042e-4912-b23e-18516b6bbe96",
|
|
||||||
"name": "inverter",
|
|
||||||
"displayName": "Solar Inverter",
|
|
||||||
"createMethods": ["auto"],
|
|
||||||
"interfaces" : ["extendedsmartmeterproducer", "connectable"],
|
|
||||||
"paramTypes": [
|
|
||||||
{
|
|
||||||
"id": "f43e8159-7337-4bd0-ba74-b6630e554e43",
|
|
||||||
"name": "id",
|
|
||||||
"displayName": "Device ID",
|
|
||||||
"type": "QString",
|
|
||||||
"readOnly": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"stateTypes": [
|
|
||||||
{
|
|
||||||
"id": "eda29c50-73ac-40e0-9c92-26fee352e688",
|
|
||||||
"name": "connected",
|
|
||||||
"displayName": "Connected",
|
|
||||||
"displayNameEvent": "Connected changed",
|
|
||||||
"type": "bool",
|
|
||||||
"defaultValue": false,
|
|
||||||
"cached": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "a804eabf-d5b8-4c83-84e4-8ec994875950",
|
|
||||||
"name": "currentPower",
|
|
||||||
"displayName": "Current power",
|
|
||||||
"displayNameEvent": "Current Power changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "Watt",
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "cd3a0abc-37cc-4f9c-8ff2-c7ccc2513880",
|
|
||||||
"name": "eday",
|
|
||||||
"displayName": "Energy of current day",
|
|
||||||
"displayNameEvent": "Energy of day changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "KiloWattHour",
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "341596ec-690b-4bf6-b6ed-0f92fa1c7d6c",
|
|
||||||
"name": "eyear",
|
|
||||||
"displayName": "Energy of current year",
|
|
||||||
"displayNameEvent": "Energy of year changed",
|
|
||||||
"type": "int",
|
|
||||||
"unit": "KiloWattHour",
|
|
||||||
"defaultValue": "0"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "6b6c1ddb-692f-400f-8b8d-38e0e0ae34ba",
|
|
||||||
"name": "totalEnergyProduced",
|
|
||||||
"displayName": "Energy total",
|
|
||||||
"displayNameEvent": "Energy total changed",
|
|
||||||
"type": "double",
|
|
||||||
"unit": "KiloWattHour",
|
|
||||||
"defaultValue": "0"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
#define SUNNYWEBBOX_H
|
#define SUNNYWEBBOX_H
|
||||||
|
|
||||||
#include "integrations/thing.h"
|
#include "integrations/thing.h"
|
||||||
#include "sunnywebboxcommunication.h"
|
#include "network/networkaccessmanager.h"
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
@ -77,11 +77,11 @@ public:
|
|||||||
~SunnyWebBox();
|
~SunnyWebBox();
|
||||||
|
|
||||||
QString getPlantOverview(); // Returns an object with the following plant data: PAC, E-TODAY, E-TOTAL, MODE, ERROR
|
QString getPlantOverview(); // Returns an object with the following plant data: PAC, E-TODAY, E-TOTAL, MODE, ERROR
|
||||||
QString getDevices(); //Returns a hierarchical list of all detected plant devices.
|
QString getDevices(); // Returns a hierarchical list of all detected plant devices.
|
||||||
QString getProcessDataChannels(const QString &deviceKey); //Returns a list with the meta names of the available process data channels for a particular device type.
|
QString getProcessDataChannels(const QString &deviceKey); //Returns a list with the meta names of the available process data channels for a particular device type.
|
||||||
QString getProcessData(const QStringList &deviceKeys); //Returns process data for up to 5 devices per request.
|
QString getProcessData(const QStringList &deviceKeys); //Returns process data for up to 5 devices per request.
|
||||||
QString getParameterChannels(const QString &deviceKey); //Returns a list with the meta names of the available parameter channels for a particular device type
|
QString getParameterChannels(const QString &deviceKey); //Returns a list with the meta names of the available parameter channels for a particular device type
|
||||||
QString getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices
|
QString getParameters(const QStringList &deviceKeys); //Returns the parameter values of up to 5 devices
|
||||||
QString setParameters(const QString &deviceKeys, const QHash<QString, QVariant> &channels); //Sets parameter values
|
QString setParameters(const QString &deviceKeys, const QHash<QString, QVariant> &channels); //Sets parameter values
|
||||||
|
|
||||||
void setHostAddress(const QHostAddress &address);
|
void setHostAddress(const QHostAddress &address);
|
||||||
@ -95,8 +95,8 @@ private:
|
|||||||
QString sendMessage(const QHostAddress &address, const QString &procedure);
|
QString sendMessage(const QHostAddress &address, const QString &procedure);
|
||||||
QString sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms);
|
QString sendMessage(const QHostAddress &address, const QString &procedure, const QJsonObject ¶ms);
|
||||||
void parseMessage(const QString &messageId, const QString &messageType, const QVariantMap &result);
|
void parseMessage(const QString &messageId, const QString &messageType, const QVariantMap &result);
|
||||||
|
|
||||||
void setConnectionStatus(bool connected);
|
void setConnectionStatus(bool connected);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectedChanged(bool connected);
|
void connectedChanged(bool connected);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user