Clean up code and set propper vendor name
parent
e20d8e8e86
commit
2b3a44cd6c
|
|
@ -40,49 +40,51 @@ IntegrationPluginSma::IntegrationPluginSma()
|
|||
|
||||
void IntegrationPluginSma::discoverThings(ThingDiscoveryInfo *info)
|
||||
{
|
||||
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
|
||||
qCWarning(dcSma()) << "Failed to discover network devices. The network device discovery is not available.";
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Unable to discover devices in your network."));
|
||||
return;
|
||||
}
|
||||
|
||||
qCDebug(dcSma()) << "Starting network discovery...";
|
||||
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||
ThingDescriptors descriptors;
|
||||
qCDebug(dcSma()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
||||
// Filter for sma hosts
|
||||
if (!networkDeviceInfo.hostName().toLower().contains("sma"))
|
||||
continue;
|
||||
|
||||
QString title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")";
|
||||
QString description;
|
||||
if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
|
||||
description = networkDeviceInfo.macAddress();
|
||||
} else {
|
||||
description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
|
||||
}
|
||||
|
||||
ThingDescriptor descriptor(sunnyWebBoxThingClassId, title, description);
|
||||
|
||||
// Check for reconfiguration
|
||||
foreach (Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString() == networkDeviceInfo.macAddress()) {
|
||||
descriptor.setThingId(existingThing->id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ParamList params;
|
||||
params << Param(sunnyWebBoxThingHostParamTypeId, networkDeviceInfo.address().toString());
|
||||
params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
||||
descriptor.setParams(params);
|
||||
descriptors.append(descriptor);
|
||||
if (info->thingClassId() == sunnyWebBoxThingClassId) {
|
||||
if (!hardwareManager()->networkDeviceDiscovery()->available()) {
|
||||
qCWarning(dcSma()) << "Failed to discover network devices. The network device discovery is not available.";
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Unable to discover devices in your network."));
|
||||
return;
|
||||
}
|
||||
info->addThingDescriptors(descriptors);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
|
||||
qCDebug(dcSma()) << "Starting network discovery...";
|
||||
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||
ThingDescriptors descriptors;
|
||||
qCDebug(dcSma()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
||||
// Filter for sma hosts
|
||||
if (!networkDeviceInfo.hostName().toLower().contains("sma"))
|
||||
continue;
|
||||
|
||||
QString title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")";
|
||||
QString description;
|
||||
if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
|
||||
description = networkDeviceInfo.macAddress();
|
||||
} else {
|
||||
description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
|
||||
}
|
||||
|
||||
ThingDescriptor descriptor(sunnyWebBoxThingClassId, title, description);
|
||||
|
||||
// Check for reconfiguration
|
||||
foreach (Thing *existingThing, myThings()) {
|
||||
if (existingThing->paramValue(sunnyWebBoxThingMacAddressParamTypeId).toString() == networkDeviceInfo.macAddress()) {
|
||||
descriptor.setThingId(existingThing->id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ParamList params;
|
||||
params << Param(sunnyWebBoxThingHostParamTypeId, networkDeviceInfo.address().toString());
|
||||
params << Param(sunnyWebBoxThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
||||
descriptor.setParams(params);
|
||||
descriptors.append(descriptor);
|
||||
}
|
||||
info->addThingDescriptors(descriptors);
|
||||
info->finish(Thing::ThingErrorNoError);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -160,7 +162,7 @@ void IntegrationPluginSma::thingRemoved(Thing *thing)
|
|||
|
||||
void IntegrationPluginSma::onRefreshTimer()
|
||||
{
|
||||
Q_FOREACH(Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) {
|
||||
foreach (Thing *thing, myThings().filterByThingClassId(sunnyWebBoxThingClassId)) {
|
||||
SunnyWebBox *sunnyWebBox = m_sunnyWebBoxes.value(thing);
|
||||
sunnyWebBox->getPlantOverview();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
{
|
||||
"id": "16d5a4a3-36d5-46c0-b7dd-df166ddf5981",
|
||||
"name": "Sma",
|
||||
"displayName": "SMA",
|
||||
"displayName": "SMA Solar Technology AG",
|
||||
"thingClasses": [
|
||||
{
|
||||
"id": "49304127-ce9b-45dd-8511-05030a4ac003",
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ QString SunnyWebBox::getProcessData(const QStringList &deviceKeys)
|
|||
{
|
||||
QJsonObject paramsObj;
|
||||
QJsonArray devicesArray;
|
||||
Q_FOREACH(QString key, deviceKeys) {
|
||||
foreach (const QString &key, deviceKeys) {
|
||||
QJsonObject deviceObj;
|
||||
deviceObj["key"] = key;
|
||||
devicesArray.append(deviceObj);
|
||||
|
|
@ -93,7 +93,7 @@ QString SunnyWebBox::getParameters(const QStringList &deviceKeys)
|
|||
{
|
||||
QJsonObject paramsObj;
|
||||
QJsonArray devicesArray;
|
||||
Q_FOREACH(QString key, deviceKeys) {
|
||||
foreach (const QString &key, deviceKeys) {
|
||||
QJsonObject deviceObj;
|
||||
deviceObj["key"] = key;
|
||||
devicesArray.append(deviceObj);
|
||||
|
|
@ -109,7 +109,7 @@ QString SunnyWebBox::setParameters(const QString &deviceKey, const QHash<QString
|
|||
QJsonObject deviceObj;
|
||||
deviceObj["key"] = deviceKey;
|
||||
QJsonArray channelsArray;
|
||||
Q_FOREACH(QString key, channels.keys()) {
|
||||
foreach (const QString &key, channels.keys()) {
|
||||
QJsonObject channelObj;
|
||||
channelObj["meta"] = key;
|
||||
channelObj["value"] = channels.value(key).toString();
|
||||
|
|
@ -148,7 +148,7 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT
|
|||
Overview overview;
|
||||
QVariantList overviewList = result.value("overview").toList();
|
||||
qCDebug(dcSma()) << "SunnyWebBox: GetPlantOverview";
|
||||
Q_FOREACH(QVariant value, overviewList) {
|
||||
foreach (const QVariant &value, overviewList) {
|
||||
QVariantMap map = value.toMap();
|
||||
|
||||
if (map["meta"].toString() == "GriPwr") {
|
||||
|
|
@ -177,7 +177,7 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT
|
|||
QList<Device> devices;
|
||||
QVariantList deviceList = result.value("devices").toList();
|
||||
qCDebug(dcSma()) << "SunnyWebBox: GetDevices" << result.value("totalDevicesReturned").toInt();
|
||||
Q_FOREACH(QVariant value, deviceList) {
|
||||
foreach (const QVariant &value, deviceList) {
|
||||
Device device;
|
||||
QVariantMap map = value.toMap();
|
||||
device.name = map["name"].toString();
|
||||
|
|
@ -185,7 +185,7 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT
|
|||
device.key = map["key"].toString();
|
||||
qCDebug(dcSma()) << "SunnyWebBox: - Key" << device.key;
|
||||
QVariantList childrenList = map["children"].toList();
|
||||
Q_FOREACH(QVariant childValue, childrenList) {
|
||||
foreach (const QVariant &childValue, childrenList) {
|
||||
Device child;
|
||||
QVariantMap childMap = childValue.toMap();
|
||||
device.name = childMap["name"].toString();
|
||||
|
|
@ -194,44 +194,43 @@ void SunnyWebBox::parseMessage(const QString &messageId, const QString &messageT
|
|||
}
|
||||
devices.append(device);
|
||||
}
|
||||
if (!devices.isEmpty())
|
||||
if (!devices.isEmpty()) {
|
||||
emit devicesReceived(messageId, devices);
|
||||
}
|
||||
} else if (messageType == "GetProcessDataChannels" ||
|
||||
messageType == "GetProDataChannels") {
|
||||
Q_FOREACH(QString deviceKey, result.keys()) {
|
||||
foreach (const QString &deviceKey, result.keys()) {
|
||||
QStringList processDataChannels = result.value(deviceKey).toStringList();
|
||||
if (!processDataChannels.isEmpty())
|
||||
emit processDataChannelsReceived(messageId, deviceKey, processDataChannels);
|
||||
}
|
||||
} else if (messageType == "GetProcessData") {
|
||||
QList<Device> devices;
|
||||
QVariantList devicesList = result.value("devices").toList();
|
||||
qCDebug(dcSma()) << "SunnyWebBox: GetProcessData response received";
|
||||
Q_FOREACH(QVariant value, devicesList) {
|
||||
foreach (const QVariant &value, devicesList) {
|
||||
|
||||
QString key = value.toMap().value("key").toString();
|
||||
QVariantList channelsList = value.toMap().value("channels").toList();
|
||||
QHash<QString, QVariant> channels;
|
||||
Q_FOREACH(QVariant channel, channelsList) {
|
||||
foreach (const QVariant &channel, channelsList) {
|
||||
channels.insert(channel.toMap().value("meta").toString(), channel.toMap().value("value"));
|
||||
}
|
||||
emit processDataReceived(messageId, key, channels);
|
||||
}
|
||||
} else if (messageType == "GetParameterChannels") {
|
||||
Q_FOREACH(QString deviceKey, result.keys()) {
|
||||
foreach (const QString &deviceKey, result.keys()) {
|
||||
QStringList parameterChannels = result.value(deviceKey).toStringList();
|
||||
if (!parameterChannels.isEmpty())
|
||||
emit parameterChannelsReceived(messageId, deviceKey, parameterChannels);
|
||||
}
|
||||
} else if (messageType == "GetParameter"|| messageType == "SetParameter") {
|
||||
QList<Device> devices;
|
||||
QVariantList devicesList = result.value("devices").toList();
|
||||
Q_FOREACH(QVariant value, devicesList) {
|
||||
foreach (const QVariant &value, devicesList) {
|
||||
|
||||
QString key = value.toMap().value("key").toString();
|
||||
QVariantList channelsList = value.toMap().value("channels").toList();
|
||||
QList<Parameter> parameters;
|
||||
Q_FOREACH(QVariant channel, channelsList) {
|
||||
foreach (const QVariant &channel, channelsList) {
|
||||
Parameter parameter;
|
||||
parameter.meta = channel.toMap().value("meta").toString();
|
||||
parameter.name = channel.toMap().value("name").toString();
|
||||
|
|
|
|||
Loading…
Reference in New Issue