Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDM: Update to networkdevice interface #191

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 33 additions & 21 deletions idm/integrationpluginidm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2022, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: [email protected]
*
* This file is part of nymea.
Expand Down Expand Up @@ -50,37 +50,49 @@ void IntegrationPluginIdm::discoverThings(ThingDiscoveryInfo *info)
qCDebug(dcIdm()) << "Discovering network...";
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors;
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [this, discoveryReply, info](){
qCDebug(dcIdm()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
qCDebug(dcIdm()) << networkDeviceInfo;
QString title;
if (networkDeviceInfo.hostName().isEmpty()) {
title += networkDeviceInfo.address().toString();
} else {
title += networkDeviceInfo.address().toString() + " (" + networkDeviceInfo.hostName() + ")";
}

QString description;
if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
description = networkDeviceInfo.macAddress();
} else {
description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
switch (networkDeviceInfo.monitorMode()) {
case NetworkDeviceInfo::MonitorModeMac:
description = networkDeviceInfo.address().toString();
if (!networkDeviceInfo.macAddressInfos().constFirst().vendorName().isEmpty())
description += " - " + networkDeviceInfo.macAddressInfos().constFirst().vendorName();

if (networkDeviceInfo.hostName().isEmpty()) {
title = networkDeviceInfo.macAddressInfos().constFirst().macAddress().toString();
} else {
title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.macAddressInfos().constFirst().macAddress().toString() + ")";
}

break;
case NetworkDeviceInfo::MonitorModeHostName:
title = networkDeviceInfo.hostName();
description = networkDeviceInfo.address().toString();
break;
case NetworkDeviceInfo::MonitorModeIp:
title = "Network device " + networkDeviceInfo.address().toString();
description = "Interface: " + networkDeviceInfo.networkInterface().name();
break;
}

ParamList params;
params << Param(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.thingParamValueAddress());
params << Param(navigator2ThingHostNameParamTypeId, networkDeviceInfo.thingParamValueHostName());
params << Param(navigator2ThingAddressParamTypeId, networkDeviceInfo.thingParamValueAddress());
ThingDescriptor descriptor(navigator2ThingClassId, title, description);
descriptor.setParams(params);

// Check if we already have set up this device
Things existingThings = myThings().filterByParam(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
if (existingThings.count() == 1) {
qCDebug(dcIdm()) << "This thing already exists in the system." << existingThings.first() << networkDeviceInfo;
descriptor.setThingId(existingThings.first()->id());
Thing *existingThing = myThings().findByParams(params);
if (existingThing) {
qCDebug(dcIdm()) << "This thing already exists in the system." << existingThing << networkDeviceInfo;
descriptor.setThingId(existingThing->id());
}

ParamList params;
params << Param(navigator2ThingMacAddressParamTypeId, networkDeviceInfo.macAddress());
descriptor.setParams(params);
info->addThingDescriptor(descriptor);
}
info->finish(Thing::ThingErrorNoError);
Expand Down Expand Up @@ -113,7 +125,7 @@ void IntegrationPluginIdm::setupThing(ThingSetupInfo *info)
}

// Create the monitor
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(macAddress);
NetworkDeviceMonitor *monitor = hardwareManager()->networkDeviceDiscovery()->registerMonitor(thing);
m_monitors.insert(thing, monitor);

QHostAddress address = monitor->networkDeviceInfo().address();
Expand Down
2 changes: 1 addition & 1 deletion idm/integrationpluginidm.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2022, nymea GmbH
* Copyright 2013 - 2024, nymea GmbH
* Contact: [email protected]
*
* This file is part of nymea.
Expand Down
19 changes: 18 additions & 1 deletion idm/integrationpluginidm.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,30 @@
"displayName": "Navigator 2.0",
"id": "1c95ac91-4eca-4cbf-b0f4-d60d35d069ed",
"createMethods": ["user", "discovery"],
"interfaces": ["thermostat", "smartmeterconsumer", "connectable" ],
"interfaces": ["thermostat", "smartmeterconsumer", "connectable", "networkdevice"],
"paramTypes": [
{
"id": "d178ca29-41a1-4f56-82ec-76a833c1de50",
"name": "macAddress",
"displayName": "MAC address",
"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": ""
}
],
Expand Down