Skip to content

Commit

Permalink
Merge PR #758: WakeOnLan: Update to new network device discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins committed Jan 9, 2025
2 parents 89e3681 + 9ffd432 commit bd30d2b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
24 changes: 11 additions & 13 deletions wakeonlan/integrationpluginwakeonlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,16 @@ void IntegrationPluginWakeOnLan::discoverThings(ThingDiscoveryInfo *info)
NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover();
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, discoveryReply, &NetworkDeviceDiscoveryReply::deleteLater);
connect(discoveryReply, &NetworkDeviceDiscoveryReply::finished, this, [=](){
ThingDescriptors descriptors;
qCDebug(dcWakeOnLan()) << "Discovery finished. Found" << discoveryReply->networkDeviceInfos().count() << "devices";
foreach (const NetworkDeviceInfo &networkDeviceInfo, discoveryReply->networkDeviceInfos()) {
// We need the mac address...
if (networkDeviceInfo.macAddress().isEmpty())

// We need a unique mac
if (networkDeviceInfo.monitorMode() != NetworkDeviceInfo::MonitorModeMac)
continue;

MacAddressInfo macInfo = networkDeviceInfo.macAddressInfos().constFirst();
// Filter out already added network devices, rediscovery is in this case no option
if (myThings().filterByParam(wolThingMacParamTypeId, networkDeviceInfo.macAddress()).count() != 0)
if (myThings().filterByParam(wolThingMacParamTypeId, macInfo.macAddress().toString()).count() != 0)
continue;

QString title;
Expand All @@ -73,25 +74,22 @@ void IntegrationPluginWakeOnLan::discoverThings(ThingDiscoveryInfo *info)
title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")";
}
QString description;
if (networkDeviceInfo.macAddressManufacturer().isEmpty()) {
description = networkDeviceInfo.macAddress();
if (macInfo.vendorName().isEmpty()) {
description = macInfo.macAddress().toString();
} else {
description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")";
description = macInfo.macAddress().toString() + " (" + macInfo.vendorName() + ")";
}
ThingDescriptor descriptor(wolThingClassId, title, description);
ParamList params;
params.append(Param(wolThingMacParamTypeId, networkDeviceInfo.macAddress()));
descriptor.setParams(params);
descriptors.append(descriptor);
descriptor.setParams({Param(wolThingMacParamTypeId, macInfo.macAddress().toString())});
info->addThingDescriptor(descriptor);
}
info->addThingDescriptors(descriptors);
info->finish(Thing::ThingErrorNoError);
});
}

void IntegrationPluginWakeOnLan::executeAction(ThingActionInfo *info)
{
qCDebug(dcWakeOnLan) << "Wake up" << info->thing()->name();
qCInfo(dcWakeOnLan) << "Wake up" << info->thing()->name();
wakeup(info->thing()->paramValue(wolThingMacParamTypeId).toString());
return info->finish(Thing::ThingErrorNoError);
}
Expand Down
3 changes: 2 additions & 1 deletion wakeonlan/integrationpluginwakeonlan.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"name": "mac",
"displayName": "MAC address",
"type": "QString",
"inputType": "MacAddress"
"inputType": "MacAddress",
"defaultValue": ""
}
],
"actionTypes": [
Expand Down

0 comments on commit bd30d2b

Please sign in to comment.