IDM: Update to networkdevice interface
parent
36f9f3c512
commit
9c0222a12b
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2022, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
@ -50,37 +50,49 @@ void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
|
||||||
qCDebug(dcIdm()) << "Discovering network...";
|
qCDebug(dcIdm()) << "Discovering network...";
|
||||||
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
|
||||||
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
|
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [this, discoveryReply, info](){
|
||||||
ThingDescriptors descriptors;
|
|
||||||
qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
|
||||||
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
|
||||||
qCDebug(dcIdm()) << networkDeviceInfo;
|
qCDebug(dcIdm()) << networkDeviceInfo;
|
||||||
QString title;
|
QString title;
|
||||||
if (networkDeviceInfo.hostName().isEmpty()) {
|
|
||||||
title += networkDeviceInfo.address().toString();
|
|
||||||
} else {
|
|
||||||
title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
QString description;
|
QString description;
|
||||||
if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
|
switch (networkDeviceInfo.monitorMode()) {
|
||||||
description = networkDeviceInfo.macAddress();
|
case NetworkDeviceInfo::MonitorModeMac:
|
||||||
} else {
|
description = networkDeviceInfo.address().toString();
|
||||||
description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
|
if (!networkDeviceInfo.macAddressInfos().constFirst().vendorName().isEmpty())
|
||||||
}
|
description += " - " + networkDeviceInfo.macAddressInfos().constFirst().vendorName();
|
||||||
|
|
||||||
ThingDescriptor descriptor(navigator2ThingClassId, title, description);
|
if (networkDeviceInfo.hostName().isEmpty()) {
|
||||||
|
title = networkDeviceInfo.macAddressInfos().constFirst().macAddress().toString();
|
||||||
|
} else {
|
||||||
|
title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.macAddressInfos().constFirst().macAddress().toString() + ")";
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we already have set up this device
|
break;
|
||||||
Things existingThings = myThings().filterByParam(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
case NetworkDeviceInfo::MonitorModeHostName:
|
||||||
if (existingThings.count() == 1) {
|
title = networkDeviceInfo.hostName();
|
||||||
qCDebug(dcIdm()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
|
description = networkDeviceInfo.address().toString();
|
||||||
descriptor.setThingId(existingThings.first()->id());
|
break;
|
||||||
|
case NetworkDeviceInfo::MonitorModeIp:
|
||||||
|
title = "Network device " + networkDeviceInfo.address().toString();
|
||||||
|
description = "Interface: " + networkDeviceInfo.networkInterface().name();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ParamList params;
|
ParamList params;
|
||||||
params << Param(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
|
params << Param(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.thingParamValueAddress());
|
||||||
|
params << Param(navigator2ThingHostNameParamTypeId, networkDeviceInfo.thingParamValueHostName());
|
||||||
|
params << Param(navigator2ThingAddressParamTypeId, networkDeviceInfo.thingParamValueAddress());
|
||||||
|
ThingDescriptor descriptor(navigator2ThingClassId, title, description);
|
||||||
descriptor.setParams(params);
|
descriptor.setParams(params);
|
||||||
|
|
||||||
|
// Check if we already have set up this device
|
||||||
|
Thing *existingThing = myThings().findByParams(params);
|
||||||
|
if (existingThing) {
|
||||||
|
qCDebug(dcIdm()) << "This thing already exists in the system." << existingThing << networkDeviceInfo;
|
||||||
|
descriptor.setThingId(existingThing->id());
|
||||||
|
}
|
||||||
|
|
||||||
info->addThingDescriptor(descriptor);
|
info->addThingDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
info->finish(Thing::ThingErrorNoError);
|
info->finish(Thing::ThingErrorNoError);
|
||||||
|
|
@ -113,7 +125,7 @@ void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the monitor
|
// Create the monitor
|
||||||
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(macAddress);
|
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(thing);
|
||||||
m_monitors.insert(thing, monitor);
|
m_monitors.insert(thing, monitor);
|
||||||
|
|
||||||
QHostAddress address = monitor->networkDeviceInfo().address();
|
QHostAddress address = monitor->networkDeviceInfo().address();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2022, nymea GmbH
|
* Copyright 2013 - 2024, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,30 @@
|
||||||
"displayName": "Navigator 2.0",
|
"displayName": "Navigator 2.0",
|
||||||
"id": "1c95ac91-4eca-4cbf-b0f4-d60d35d069ed",
|
"id": "1c95ac91-4eca-4cbf-b0f4-d60d35d069ed",
|
||||||
"createMethods": ["user", "discovery"],
|
"createMethods": ["user", "discovery"],
|
||||||
"interfaces": ["thermostat", "smartmeterconsumer", "connectable" ],
|
"interfaces": ["thermostat", "smartmeterconsumer", "connectable", "networkdevice"],
|
||||||
"paramTypes": [
|
"paramTypes": [
|
||||||
{
|
{
|
||||||
"id": "d178ca29-41a1-4f56-82ec-76a833c1de50",
|
"id": "d178ca29-41a1-4f56-82ec-76a833c1de50",
|
||||||
"name": "macAddress",
|
"name": "macAddress",
|
||||||
"displayName": "MAC address",
|
"displayName": "MAC address",
|
||||||
"type": "QString",
|
"type": "QString",
|
||||||
|
"inputType": "MacAddress",
|
||||||
|
"defaultValue": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "c3cc7351-ab16-4bab-9d92-0588c82e6180",
|
||||||
|
"name": "hostName",
|
||||||
|
"displayName": "Host name",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "TextLine",
|
||||||
|
"defaultValue": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "63114206-3b76-4a9e-8510-cb552d3e32c2",
|
||||||
|
"name": "address",
|
||||||
|
"displayName": "IP address",
|
||||||
|
"type": "QString",
|
||||||
|
"inputType": "IPv4Address",
|
||||||
"defaultValue": ""
|
"defaultValue": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue