added changes requested by reviewer
This commit is contained in:
parent
483542fd16
commit
3b0ee6f2a8
@ -42,7 +42,7 @@ public:
|
||||
|
||||
QString activity() const;
|
||||
void setActivity(const QString &activity);
|
||||
Thing* inverterThing() const;
|
||||
|
||||
QUrl updateUrl();
|
||||
void updateThingInfo(const QByteArray &data);
|
||||
QUrl activityUrl();
|
||||
|
||||
@ -48,16 +48,6 @@ void FroniusStorage::setChargingState(const QString &charging_state)
|
||||
m_charging_state = charging_state;
|
||||
}
|
||||
|
||||
int FroniusStorage::charge() const
|
||||
{
|
||||
return m_charge;
|
||||
}
|
||||
|
||||
void FroniusStorage::setCharge(const int &charge)
|
||||
{
|
||||
m_charge = charge;
|
||||
}
|
||||
|
||||
QUrl FroniusStorage::updateUrl()
|
||||
{
|
||||
QUrl requestUrl;
|
||||
|
||||
@ -44,9 +44,6 @@ public:
|
||||
QString charging_state() const;
|
||||
void setChargingState(const QString &charging_state);
|
||||
|
||||
int charge() const;
|
||||
void setCharge(const int &charge);
|
||||
|
||||
QUrl updateUrl();
|
||||
void updateThingInfo(const QByteArray &data);
|
||||
QUrl activityUrl();
|
||||
@ -55,6 +52,5 @@ public:
|
||||
private:
|
||||
QString m_charging_state;
|
||||
int m_charge;
|
||||
|
||||
};
|
||||
#endif // FRONIUSSTORAGE_H
|
||||
|
||||
@ -72,7 +72,7 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
|
||||
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, info, thing, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, info, [this, info, thing, reply]() {
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
@ -97,111 +97,24 @@ void IntegrationPluginFronius::setupThing(ThingSetupInfo *info)
|
||||
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
//Async Setup
|
||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
||||
|
||||
FroniusInverter *newInverter = new FroniusInverter(thing,this);
|
||||
newInverter->setDeviceId(thing->paramValue(inverterThingIdParamTypeId).toString());
|
||||
newInverter->setBaseUrl(thing->paramValue(inverterThingBaseParamTypeId).toString());
|
||||
newInverter->setHostAddress(thing->paramValue(inverterThingHostParamTypeId).toString());
|
||||
|
||||
m_froniusInverters.insert(newInverter,thing);
|
||||
|
||||
// get inverter unique ID
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(newInverter->hostAddress());
|
||||
requestUrl.setPath(newInverter->baseUrl() + "GetInverterInfo.cgi");
|
||||
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, info, newInverter, reply]() {
|
||||
QByteArray data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Device not reachable");
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the rawdata to a json document
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check reply information
|
||||
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
||||
// check for thing id in reply
|
||||
if (dataMap.contains(newInverter->deviceId())) {
|
||||
qCDebug(dcFronius()) << "Found Thing with unique:" << dataMap.value(newInverter->deviceId()).toMap().value("UniqueID").toString();
|
||||
newInverter->setUniqueId(dataMap.value(newInverter->deviceId()).toMap().value("UniqueID").toString());
|
||||
newInverter->pluginThing()->setParamValue(inverterThingUniqueIdParamTypeId,newInverter->uniqueId());
|
||||
qCDebug(dcFronius()) << "Stored unique ID:" << newInverter->uniqueId();
|
||||
}
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
// Async Setup
|
||||
} else if (thing->thingClassId() == storageThingClassId) {
|
||||
|
||||
FroniusStorage *newStorage = new FroniusStorage(thing, this);
|
||||
newStorage->setDeviceId(thing->paramValue(storageThingIdParamTypeId).toString());
|
||||
newStorage->setBaseUrl(thing->paramValue(storageThingBaseParamTypeId).toString());
|
||||
newStorage->setHostAddress(thing->paramValue(storageThingHostParamTypeId).toString());
|
||||
m_froniusStorages.insert(newStorage,thing);
|
||||
|
||||
// Get storage manufacturer and maximum capacity
|
||||
QUrlQuery query;
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(newStorage->hostAddress());
|
||||
requestUrl.setPath(newStorage->baseUrl() + "GetStorageRealtimeData.cgi");
|
||||
query.addQueryItem("Scope","Device");
|
||||
query.addQueryItem("DeviceId", newStorage->deviceId());
|
||||
requestUrl.setQuery(query);
|
||||
qCDebug(dcFronius()) << "Get Storage Data at address" << requestUrl.toString();
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, info, newStorage, reply]() {
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the rawdata to a json document
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure, tr("Please try again"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create StorageInfo list map
|
||||
QVariantMap storageInfoMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap().value("Controller").toMap();
|
||||
|
||||
newStorage->pluginThing()->setParamValue(storageThingManufacturerParamTypeId, storageInfoMap.value("Details").toMap().value("Manufacturer").toString());
|
||||
newStorage->pluginThing()->setParamValue(storageThingCapacityParamTypeId, storageInfoMap.value("Capacity_Maximum").toInt());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
//Async Setup
|
||||
} else if (thing->thingClassId() == meterThingClassId) {
|
||||
|
||||
FroniusMeter *newMeter = new FroniusMeter(thing, this);;
|
||||
newMeter->setDeviceId(thing->paramValue(meterThingIdParamTypeId).toString());
|
||||
newMeter->setBaseUrl(thing->paramValue(meterThingBaseParamTypeId).toString());
|
||||
newMeter->setHostAddress(thing->paramValue(meterThingHostParamTypeId).toString());
|
||||
|
||||
m_froniusMeters.insert(newMeter, thing);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
//Async setup
|
||||
} else if ((thing->thingClassId() == inverterThingClassId) ||
|
||||
(thing->thingClassId() == meterThingClassId) ||
|
||||
(thing->thingClassId() == storageThingClassId)) {
|
||||
Thing *loggerThing = myThings().findById(thing->parentId());
|
||||
if (!loggerThing) {
|
||||
qCWarning(dcFronius()) << "Could not find Logger Thing for thing " << thing->name();
|
||||
return info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
||||
}
|
||||
if (!loggerThing->setupComplete()) {
|
||||
//wait for the parent to finish the setup process
|
||||
connect(loggerThing, &Thing::setupStatusChanged, info, [this, info, loggerThing] {
|
||||
if (loggerThing->setupComplete())
|
||||
setupChild(info, loggerThing);
|
||||
});
|
||||
return;
|
||||
}
|
||||
setupChild(info, loggerThing);
|
||||
} else {
|
||||
Q_ASSERT_X(false, "setupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
}
|
||||
@ -230,12 +143,11 @@ void IntegrationPluginFronius::postSetupThing(Thing *thing)
|
||||
|
||||
if (thing->thingClassId() == dataloggerThingClassId) {
|
||||
searchNewThings(m_froniusLoggers.key(thing));
|
||||
thing->setStateValue(dataloggerConnectedStateTypeId, true);
|
||||
updateThingStates(thing);
|
||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
||||
updateThingStates(thing);
|
||||
} else if (thing->thingClassId() == meterThingClassId) {
|
||||
updateThingStates(thing);
|
||||
} else if (thing->thingClassId() == storageThingClassId) {
|
||||
} else if ((thing->thingClassId() == inverterThingClassId) ||
|
||||
(thing->thingClassId() == meterThingClassId) ||
|
||||
(thing->thingClassId() == storageThingClassId)) {
|
||||
updateThingStates(thing);
|
||||
} else {
|
||||
Q_ASSERT_X(false, "postSetupThing", QString("Unhandled thingClassId: %1").arg(thing->thingClassId().toString()).toUtf8());
|
||||
@ -301,7 +213,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
if(thing->thingClassId() == inverterThingClassId) {
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusInverters.key(thing)->updateUrl()));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
|
||||
@ -314,7 +226,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
});
|
||||
QNetworkReply *next_reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusInverters.key(thing)->activityUrl()));
|
||||
connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater);
|
||||
connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() {
|
||||
connect(next_reply, &QNetworkReply::finished, this, [this, thing, next_reply]() {
|
||||
if (next_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url();
|
||||
return;
|
||||
@ -327,7 +239,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
} else if (thing->thingClassId() == dataloggerThingClassId) {
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusLoggers.key(thing)->updateUrl()));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
|
||||
@ -342,7 +254,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
} else if (thing->thingClassId() == meterThingClassId) {
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusMeters.key(thing)->updateUrl()));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() {
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
|
||||
return;
|
||||
@ -356,7 +268,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
} else if (thing->thingClassId() == storageThingClassId) {
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusStorages.key(thing)->updateUrl()));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, thing, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, thing, reply]() {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
|
||||
@ -369,7 +281,7 @@ void IntegrationPluginFronius::updateThingStates(Thing *thing)
|
||||
});
|
||||
QNetworkReply *next_reply = hardwareManager()->networkManager()->get(QNetworkRequest(m_froniusStorages.key(thing)->activityUrl()));
|
||||
connect(next_reply, &QNetworkReply::finished, next_reply, &QNetworkReply::deleteLater);
|
||||
connect(next_reply, &QNetworkReply::finished, [this, thing, next_reply]() {
|
||||
connect(next_reply, &QNetworkReply::finished, this, [this, thing, next_reply]() {
|
||||
next_reply->deleteLater();
|
||||
if (next_reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << next_reply->error() << next_reply->errorString() << next_reply->request().url();
|
||||
@ -401,7 +313,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
||||
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(request);
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, [this, logger, reply]() {
|
||||
connect(reply, &QNetworkReply::finished, this, [this, logger, reply]() {
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Network request error:" << reply->error() << reply->errorString() << reply->request().url();
|
||||
@ -432,14 +344,11 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
||||
QVariantMap inverterMap = bodyMap.value("Data").toMap().value("Inverter").toMap();
|
||||
foreach (QString inverterId, inverterMap.keys()) {
|
||||
//check if thing already connected to logger
|
||||
if(!existingThing(inverterThingIdParamTypeId,inverterId)) {
|
||||
if(!thingExists(inverterThingIdParamTypeId,inverterId)) {
|
||||
QString thingName = loggerThing->name() + " Inverter " + inverterId;
|
||||
ThingDescriptor descriptor(inverterThingClassId, thingName, "Fronius Solar Inverter", loggerThing->id());
|
||||
ParamList params;
|
||||
params.append(Param(inverterThingHostParamTypeId, m_froniusLoggers.key(loggerThing)->hostAddress()));
|
||||
params.append(Param(inverterThingBaseParamTypeId, m_froniusLoggers.key(loggerThing)->baseUrl()));
|
||||
params.append(Param(inverterThingIdParamTypeId, inverterId));
|
||||
params.append(Param(inverterThingUniqueIdParamTypeId, ""));
|
||||
descriptor.setParams(params);
|
||||
thingDescriptors.append(descriptor);
|
||||
}
|
||||
@ -449,14 +358,11 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
||||
QVariantMap meterMap = bodyMap.value("Data").toMap().value("Meter").toMap();
|
||||
foreach (QString meterId, meterMap.keys()) {
|
||||
//check if thing already connected to logger
|
||||
if(!existingThing(meterThingIdParamTypeId, meterId)) {
|
||||
if(!thingExists(meterThingIdParamTypeId, meterId)) {
|
||||
QString thingName = loggerThing->name() + " Meter " + meterId;
|
||||
ThingDescriptor descriptor(meterThingClassId, thingName, "Fronius Solar Meter", loggerThing->id());
|
||||
ParamList params;
|
||||
params.append(Param(meterThingHostParamTypeId, m_froniusLoggers.key(loggerThing)->hostAddress()));
|
||||
params.append(Param(meterThingBaseParamTypeId, m_froniusLoggers.key(loggerThing)->baseUrl()));
|
||||
params.append(Param(meterThingIdParamTypeId, meterId));
|
||||
params.append(Param(meterThingUniqueIdParamTypeId, meterMap.value(meterId).toMap().value("Serial").toString()));
|
||||
descriptor.setParams(params);
|
||||
thingDescriptors.append(descriptor);
|
||||
}
|
||||
@ -466,16 +372,13 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
||||
QVariantMap storageMap = bodyMap.value("Data").toMap().value("Storage").toMap();
|
||||
foreach (QString storageId, storageMap.keys()) {
|
||||
//check if thing already connected to logger
|
||||
if(!existingThing(storageThingIdParamTypeId,storageId)) {
|
||||
if(!thingExists(storageThingIdParamTypeId,storageId)) {
|
||||
QString thingName = loggerThing->name() + " Storage " + storageId;
|
||||
ThingDescriptor descriptor(storageThingClassId, thingName, "Fronius Solar Storage", loggerThing->id());
|
||||
ParamList params;
|
||||
params.append(Param(storageThingManufacturerParamTypeId, ""));
|
||||
params.append(Param(storageThingCapacityParamTypeId, ""));
|
||||
params.append(Param(storageThingHostParamTypeId, m_froniusLoggers.key(loggerThing)->hostAddress()));
|
||||
params.append(Param(storageThingBaseParamTypeId, m_froniusLoggers.key(loggerThing)->baseUrl()));
|
||||
params.append(Param(storageThingIdParamTypeId, storageId));
|
||||
params.append(Param(storageThingUniqueIdParamTypeId, storageMap.value(storageId).toMap().value("Serial").toString()));
|
||||
descriptor.setParams(params);
|
||||
thingDescriptors.append(descriptor);
|
||||
}
|
||||
@ -503,7 +406,7 @@ void IntegrationPluginFronius::searchNewThings(FroniusLogger *logger)
|
||||
});
|
||||
}
|
||||
|
||||
bool IntegrationPluginFronius::existingThing(ParamTypeId thingParamId, QString thingId)
|
||||
bool IntegrationPluginFronius::thingExists(ParamTypeId thingParamId, QString thingId)
|
||||
{
|
||||
foreach(Thing *thing, myThings()) {
|
||||
if(thing->paramValue(thingParamId).toString() == thingId) {
|
||||
@ -513,3 +416,106 @@ bool IntegrationPluginFronius::existingThing(ParamTypeId thingParamId, QString t
|
||||
return false;
|
||||
}
|
||||
|
||||
void IntegrationPluginFronius::setupChild(ThingSetupInfo *info, Thing *loggerThing)
|
||||
{
|
||||
Thing *thing = info->thing();
|
||||
|
||||
if (thing->thingClassId() == storageThingClassId) {
|
||||
FroniusStorage *newStorage = new FroniusStorage(thing, this);
|
||||
newStorage->setDeviceId(thing->paramValue(storageThingIdParamTypeId).toString());
|
||||
newStorage->setBaseUrl(m_froniusLoggers.key(loggerThing)->baseUrl());
|
||||
newStorage->setHostAddress(m_froniusLoggers.key(loggerThing)->hostAddress());
|
||||
|
||||
// Get storage manufacturer and maximum capacity
|
||||
QUrlQuery query;
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(newStorage->hostAddress());
|
||||
requestUrl.setPath(newStorage->baseUrl() + "GetStorageRealtimeData.cgi");
|
||||
query.addQueryItem("Scope","Device");
|
||||
query.addQueryItem("DeviceId", newStorage->deviceId());
|
||||
requestUrl.setQuery(query);
|
||||
qCDebug(dcFronius()) << "Get Storage Data at address" << requestUrl.toString();
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, info, [this, info, newStorage, reply]() {
|
||||
QByteArray data = reply->readAll();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the rawdata to a json document
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
info->finish(Thing::ThingErrorHardwareFailure, tr("Please try again"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Create StorageInfo list map
|
||||
QVariantMap storageInfoMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap().value("Controller").toMap();
|
||||
|
||||
newStorage->pluginThing()->setParamValue(storageThingManufacturerParamTypeId, storageInfoMap.value("Details").toMap().value("Manufacturer").toString());
|
||||
newStorage->pluginThing()->setParamValue(storageThingCapacityParamTypeId, storageInfoMap.value("Capacity_Maximum").toInt());
|
||||
m_froniusStorages.insert(newStorage, info->thing());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
} else if (thing->thingClassId() == inverterThingClassId) {
|
||||
FroniusInverter *newInverter = new FroniusInverter(thing,this);
|
||||
newInverter->setDeviceId(thing->paramValue(inverterThingIdParamTypeId).toString());
|
||||
newInverter->setBaseUrl(m_froniusLoggers.key(loggerThing)->baseUrl());
|
||||
newInverter->setHostAddress(m_froniusLoggers.key(loggerThing)->hostAddress());
|
||||
|
||||
// get inverter unique ID
|
||||
QUrl requestUrl;
|
||||
requestUrl.setScheme("http");
|
||||
requestUrl.setHost(newInverter->hostAddress());
|
||||
requestUrl.setPath(newInverter->baseUrl() + "GetInverterInfo.cgi");
|
||||
|
||||
QNetworkReply *reply = hardwareManager()->networkManager()->get(QNetworkRequest(requestUrl));
|
||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, info, [this, info, newInverter, reply]() {
|
||||
QByteArray data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Network request error:" << reply->error() << reply->errorString();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Device not reachable");
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert the rawdata to a json document
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
qCWarning(dcFronius()) << "Fronius: Failed to parse JSON data" << data << ":" << error.errorString();
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, "Please try again");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check reply information
|
||||
QVariantMap dataMap = jsonDoc.toVariant().toMap().value("Body").toMap().value("Data").toMap();
|
||||
// check for thing id in reply
|
||||
if (dataMap.contains(newInverter->deviceId())) {
|
||||
qCDebug(dcFronius()) << "Found Thing with unique:" << dataMap.value(newInverter->deviceId()).toMap().value("UniqueID").toString();
|
||||
newInverter->setUniqueId(dataMap.value(newInverter->deviceId()).toMap().value("UniqueID").toString());
|
||||
qCDebug(dcFronius()) << "Stored unique ID:" << newInverter->uniqueId();
|
||||
}
|
||||
|
||||
m_froniusInverters.insert(newInverter, info->thing());
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
} else if (thing->thingClassId() == meterThingClassId) {
|
||||
FroniusMeter *newMeter = new FroniusMeter(thing, this);;
|
||||
newMeter->setDeviceId(thing->paramValue(meterThingIdParamTypeId).toString());
|
||||
newMeter->setBaseUrl(m_froniusLoggers.key(loggerThing)->baseUrl());
|
||||
newMeter->setHostAddress(m_froniusLoggers.key(loggerThing)->hostAddress());
|
||||
|
||||
m_froniusMeters.insert(newMeter, thing);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,9 @@ private:
|
||||
void updateThingStates(Thing *thing);
|
||||
|
||||
void searchNewThings(FroniusLogger *logger);
|
||||
bool existingThing(ParamTypeId thingParamId, QString thingId);
|
||||
bool thingExists(ParamTypeId thingParamId, QString thingId);
|
||||
|
||||
void setupChild(ThingSetupInfo *info, Thing *parentThing);
|
||||
};
|
||||
|
||||
#endif // INTEGRATIONPLUGINFRONIUS_H
|
||||
|
||||
@ -153,33 +153,13 @@
|
||||
"createMethods": ["auto"],
|
||||
"interfaces" : ["extendedsmartmeterproducer", "connectable"],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "1aa82e12-ee8c-4142-8b89-a4f1e85556d0",
|
||||
"name": "host",
|
||||
"displayName": "Host address",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "ec1f792a-b453-49f0-8ea6-677ad3c25a5c",
|
||||
"name": "base",
|
||||
"displayName": "Base url",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "f2f8c2f5-dd6a-4786-b336-82fc84e5bb98",
|
||||
"name": "id",
|
||||
"displayName": "Device id",
|
||||
"displayName": "Device ID",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "8fadc0e8-9d69-4b9d-b493-b6ac3eb59c49",
|
||||
"name": "uniqueId",
|
||||
"displayName": "Unique id",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
"inputType": "TextLine",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -189,7 +169,8 @@
|
||||
"displayName": "Reachable",
|
||||
"displayNameEvent": "Reachable changed",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
"defaultValue": false,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "e763baa7-5eaf-438c-83f0-4fa6c0f7eeb0",
|
||||
@ -240,37 +221,17 @@
|
||||
{
|
||||
"id": "c3cb53a4-32dd-434d-9d9c-aada41f8129c",
|
||||
"name": "meter",
|
||||
"displayName": "Fronius Smart Meter",
|
||||
"displayName": "Fronius smart meter",
|
||||
"createMethods": ["auto"],
|
||||
"interfaces": [ "extendedsmartmeterconsumer", "extendedsmartmeterproducer", "connectable" ],
|
||||
"paramTypes": [
|
||||
{
|
||||
"id": "ddcb8689-b0b8-4b94-b022-4ce4cf9e0ec2",
|
||||
"name": "host",
|
||||
"displayName": "Address",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "2cb4acd6-a663-48c3-8366-ab538c7b4e7d",
|
||||
"name": "base",
|
||||
"displayName": "Base URL",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "cf3a7025-d368-475a-8f48-efc1344a8409",
|
||||
"name": "id",
|
||||
"displayName": "Device ID",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "285eabb2-47c8-4406-8123-6621b21558c1",
|
||||
"name": "uniqueId",
|
||||
"displayName": "Unique ID",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
"inputType": "TextLine",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -280,7 +241,8 @@
|
||||
"displayName": "Reachable",
|
||||
"displayNameEvent": "Reachable changed",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
"defaultValue": false,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "e5056ea1-88a2-410b-9c5e-6322aca4cb17",
|
||||
@ -294,7 +256,7 @@
|
||||
{
|
||||
"id": "ca14cca5-d9f0-49c5-a8f7-907d4c0825f0",
|
||||
"name": "totalEnergyProduced",
|
||||
"displayName": "Energy Produced",
|
||||
"displayName": "Energy produced",
|
||||
"displayNameEvent": "Energy production changed",
|
||||
"type": "double",
|
||||
"unit": "KiloWattHour",
|
||||
@ -314,7 +276,7 @@
|
||||
{
|
||||
"id": "b00139fa-7386-48b1-8697-2fdd21a57ced",
|
||||
"name": "storage",
|
||||
"displayName": "Fronius Solar Storage",
|
||||
"displayName": "Fronius solar storage",
|
||||
"createMethods": ["auto"],
|
||||
"interfaces": [ "batterylevel", "connectable" ],
|
||||
"paramTypes": [
|
||||
@ -323,42 +285,24 @@
|
||||
"name": "manufacturer",
|
||||
"displayName": "Manufacturer",
|
||||
"type": "QString",
|
||||
"defaultValue": "TextLine"
|
||||
"defaultValue": "TextLine",
|
||||
"readOnly": true
|
||||
},
|
||||
{
|
||||
"id": "59a68e91-1aad-46b7-b351-03b7b2216366",
|
||||
"name": "capacity",
|
||||
"displayName": "Maxmimum capacity",
|
||||
"type": "QString",
|
||||
"defaultValue": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "84bd8a41-2411-4bb0-87a9-ab7e01044b10",
|
||||
"name": "host",
|
||||
"displayName": "Address",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "d19b5d81-4e62-48be-bad6-287b0019274a",
|
||||
"name": "base",
|
||||
"displayName": "Base URL",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
"defaultValue": "TextLine",
|
||||
"readOnly": true
|
||||
},
|
||||
{
|
||||
"id": "49087f31-abf5-4bb8-946b-a3626ee80566",
|
||||
"name": "id",
|
||||
"displayName": "Device ID",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
},
|
||||
{
|
||||
"id": "0d62432a-38bc-48b8-99d2-895f17fcf0b2",
|
||||
"name": "uniqueId",
|
||||
"displayName": "Unique ID",
|
||||
"type": "QString",
|
||||
"inputType": "TextLine"
|
||||
"inputType": "TextLine",
|
||||
"readOnly": true
|
||||
}
|
||||
],
|
||||
"stateTypes": [
|
||||
@ -368,7 +312,8 @@
|
||||
"displayName": "Reachable",
|
||||
"displayNameEvent": "Reachable changed",
|
||||
"type": "bool",
|
||||
"defaultValue": false
|
||||
"defaultValue": false,
|
||||
"cached": false
|
||||
},
|
||||
{
|
||||
"id": "2de34a1f-de2e-43ad-8998-8a5460dff9ae",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user