Add network discovery to the sunspec plugin
This commit is contained in:
parent
6b8469177f
commit
d9138ff01d
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "plugininfo.h"
|
#include "plugininfo.h"
|
||||||
#include "integrationpluginsunspec.h"
|
#include "integrationpluginsunspec.h"
|
||||||
|
#include "network/networkdevicediscovery.h"
|
||||||
|
|
||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
|
|
||||||
@ -98,6 +99,46 @@ void IntegrationPluginSunSpec::init()
|
|||||||
m_frequencyStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseMeterFrequencyStateTypeId);
|
m_frequencyStateTypeIds.insert(sunspecThreePhaseMeterThingClassId, sunspecThreePhaseMeterFrequencyStateTypeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IntegrationPluginSunSpec::discoverThings(ThingDiscoveryInfo *info)
|
||||||
|
{
|
||||||
|
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||||
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
||||||
|
ThingDescriptors descriptors;
|
||||||
|
qCDebug(dcSunSpec()) << "Discovery finished. Found" << discoveryReply->networkDevices().count() << "devices";
|
||||||
|
foreach (const NetworkDevice &networkDevice, discoveryReply->networkDevices()) {
|
||||||
|
qCDebug(dcSunSpec()) << networkDevice;
|
||||||
|
QString title;
|
||||||
|
if (networkDevice.hostName().isEmpty()) {
|
||||||
|
title += networkDevice.address().toString();
|
||||||
|
} else {
|
||||||
|
title += networkDevice.address().toString() + " (" + networkDevice.hostName() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString description;
|
||||||
|
if (networkDevice.macAddressManufacturer().isEmpty()) {
|
||||||
|
description = networkDevice.macAddress();
|
||||||
|
} else {
|
||||||
|
description = networkDevice.macAddress() + " (" + networkDevice.macAddressManufacturer() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
ThingDescriptor descriptor(sunspecConnectionThingClassId, title, description);
|
||||||
|
|
||||||
|
// Check if we already have set up this device
|
||||||
|
Things existingThings = myThings().filterByParam(sunspecConnectionThingIpAddressParamTypeId, networkDevice.address().toString());
|
||||||
|
if (existingThings.count() == 1) {
|
||||||
|
qCDebug(dcSunSpec()) << "This thing already exists in the system." << existingThings.first() << networkDevice;
|
||||||
|
descriptor.setThingId(existingThings.first()->id());
|
||||||
|
}
|
||||||
|
|
||||||
|
ParamList params;
|
||||||
|
params << Param(sunspecConnectionThingIpAddressParamTypeId, networkDevice.address().toString());
|
||||||
|
descriptor.setParams(params);
|
||||||
|
info->addThingDescriptor(descriptor);
|
||||||
|
}
|
||||||
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info)
|
void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info)
|
||||||
{
|
{
|
||||||
Thing *thing = info->thing();
|
Thing *thing = info->thing();
|
||||||
@ -132,7 +173,7 @@ void IntegrationPluginSunSpec::setupThing(ThingSetupInfo *info)
|
|||||||
});
|
});
|
||||||
|
|
||||||
connect(info, &ThingSetupInfo::aborted, sunSpec, &SunSpec::deleteLater);
|
connect(info, &ThingSetupInfo::aborted, sunSpec, &SunSpec::deleteLater);
|
||||||
connect(sunSpec, &SunSpec::destroyed, [this, thing] {
|
connect(sunSpec, &SunSpec::destroyed, thing, [this, thing] {
|
||||||
m_sunSpecConnections.remove(thing->id());
|
m_sunSpecConnections.remove(thing->id());
|
||||||
});
|
});
|
||||||
connect(sunSpec, &SunSpec::foundSunSpecModel, this, &IntegrationPluginSunSpec::onFoundSunSpecModel);
|
connect(sunSpec, &SunSpec::foundSunSpecModel, this, &IntegrationPluginSunSpec::onFoundSunSpecModel);
|
||||||
|
|||||||
@ -52,6 +52,7 @@ class IntegrationPluginSunSpec: public IntegrationPlugin
|
|||||||
public:
|
public:
|
||||||
explicit IntegrationPluginSunSpec();
|
explicit IntegrationPluginSunSpec();
|
||||||
void init() override;
|
void init() 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 thingRemoved(Thing *thing) override;
|
void thingRemoved(Thing *thing) override;
|
||||||
|
|||||||
@ -39,7 +39,7 @@
|
|||||||
"name": "sunspecConnection",
|
"name": "sunspecConnection",
|
||||||
"displayName": "SunSpec connection",
|
"displayName": "SunSpec connection",
|
||||||
"id": "f51853f3-8815-4cf3-b337-45cda1f3e6d5",
|
"id": "f51853f3-8815-4cf3-b337-45cda1f3e6d5",
|
||||||
"createMethods": [ "User" ],
|
"createMethods": [ "User", "Discovery" ],
|
||||||
"interfaces": ["gateway"],
|
"interfaces": ["gateway"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user