diff --git a/wakeonlan/integrationpluginwakeonlan.cpp b/wakeonlan/integrationpluginwakeonlan.cpp index 5b85d3c4..f4b1bf0b 100644 --- a/wakeonlan/integrationpluginwakeonlan.cpp +++ b/wakeonlan/integrationpluginwakeonlan.cpp @@ -33,6 +33,8 @@ #include "integrations/thing.h" #include "plugininfo.h" +#include "network/networkdevicediscovery.h" + #include #include #include @@ -41,6 +43,51 @@ IntegrationPluginWakeOnLan::IntegrationPluginWakeOnLan() { } +void IntegrationPluginWakeOnLan::discoverThings(ThingDiscoveryInfo *info) +{ + if (!hardwareManager()->networkDeviceDiscovery()->available()) { + qCWarning(dcWakeOnLan()) << "Failed to discover network devices. The network device discovery is not available."; + info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Unable to discovery devices in your network.")); + return; + } + + qCDebug(dcWakeOnLan()) << "Starting network discovery..."; + NetworkDeviceDiscoveryReply *discoveryReply = hardwareManager()->networkDeviceDiscovery()->discover(); + 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()) + continue; + + // Filter out already added network devices, rediscovery is in this case no option + if (myThings().filterByParam(wolThingMacParamTypeId, networkDeviceInfo.macAddress()).count() != 0) + continue; + + QString title; + if (networkDeviceInfo.hostName().isEmpty()) { + title = networkDeviceInfo.address().toString(); + } else { + title = networkDeviceInfo.hostName() + " (" + networkDeviceInfo.address().toString() + ")"; + } + QString description; + if (networkDeviceInfo.macAddressManufacturer().isEmpty()) { + description = networkDeviceInfo.macAddress(); + } else { + description = networkDeviceInfo.macAddress() + " (" + networkDeviceInfo.macAddressManufacturer() + ")"; + } + ThingDescriptor descriptor(wolThingClassId, title, description); + ParamList params; + params.append(Param(wolThingMacParamTypeId, networkDeviceInfo.macAddress())); + descriptor.setParams(params); + descriptors.append(descriptor); + } + info->addThingDescriptors(descriptors); + info->finish(Thing::ThingErrorNoError); + }); +} + void IntegrationPluginWakeOnLan::executeAction(ThingActionInfo *info) { qCDebug(dcWakeOnLan) << "Wake up" << info->thing()->name(); @@ -48,12 +95,12 @@ void IntegrationPluginWakeOnLan::executeAction(ThingActionInfo *info) return info->finish(Thing::ThingErrorNoError); } -void IntegrationPluginWakeOnLan::wakeup(QString mac) +void IntegrationPluginWakeOnLan::wakeup(const QString &macAddress) { const char header[] = {char(0xff), char(0xff), char(0xff), char(0xff), char(0xff), char(0xff)}; QByteArray packet = QByteArray::fromRawData(header, sizeof(header)); for(int i = 0; i < 16; ++i) { - packet.append(QByteArray::fromHex(mac.remove(':').toLocal8Bit())); + packet.append(QByteArray::fromHex(QString(macAddress).remove(':').toLocal8Bit())); } qCDebug(dcWakeOnLan) << "Created magic packet:" << packet.toHex(); QUdpSocket udpSocket; diff --git a/wakeonlan/integrationpluginwakeonlan.h b/wakeonlan/integrationpluginwakeonlan.h index fb63302c..8116612a 100644 --- a/wakeonlan/integrationpluginwakeonlan.h +++ b/wakeonlan/integrationpluginwakeonlan.h @@ -45,10 +45,12 @@ class IntegrationPluginWakeOnLan : public IntegrationPlugin public: explicit IntegrationPluginWakeOnLan(); + void discoverThings(ThingDiscoveryInfo *info) override; + void executeAction(ThingActionInfo *info) override; private slots: - void wakeup(QString mac); + void wakeup(const QString &macAddress); }; diff --git a/wakeonlan/integrationpluginwakeonlan.json b/wakeonlan/integrationpluginwakeonlan.json index d79ca7ff..88ca3373 100644 --- a/wakeonlan/integrationpluginwakeonlan.json +++ b/wakeonlan/integrationpluginwakeonlan.json @@ -12,7 +12,7 @@ "id": "3c8f2447-dcd0-4882-8c09-99e579e4d24c", "name": "wol", "displayName": "Wake On Lan", - "createMethods": ["user"], + "createMethods": ["user", "discovery"], "interfaces": ["outputtrigger"], "paramTypes": [ { diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-cs.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-cs.ts index 3bd7e693..7e72cad0 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-cs.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-cs.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake on Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) mac - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol probudit zařízení diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-da.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-da.ts index 7074c58e..113513e7 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-da.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-da.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake On Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) MAC adresse - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol vækningsservice diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-de.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-de.ts index 7e90bd0e..eff0fea8 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-de.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-de.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on LAN - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake On Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) MAC Adresse - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol Gerät aufwecken diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-en_US.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-en_US.ts index 6ed08e2c..6bc8bb3d 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-en_US.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-en_US.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-es.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-es.ts index e8476ec0..0768b74f 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-es.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-es.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake On Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) Dirección MAC - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol dispositivo para levantarse diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-fr.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-fr.ts index 03a8dd0e..1d19ac54 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-fr.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-fr.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on LAN - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake on LAN - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) Adresse Mac - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol Réveiller l'appareil diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-it.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-it.ts index f5300150..5fa7167d 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-it.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-it.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake On Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) Indirizzo MAC - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol dispositivo wake up diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-nl.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-nl.ts index f51fbb9c..09ae35e9 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-nl.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-nl.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake on Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) Mac adres - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol ontwaak-apparaat diff --git a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-pt.ts b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-pt.ts index 6573c1fa..656c24a0 100644 --- a/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-pt.ts +++ b/wakeonlan/translations/b5a87848-de56-451e-84a6-edd26ad4958f-pt.ts @@ -1,34 +1,42 @@ + + IntegrationPluginWakeOnLan + + + Unable to discovery devices in your network. + + + WakeOnLan - + Wake on Lan The name of the plugin WakeOnLan ({b5a87848-de56-451e-84a6-edd26ad4958f}) Wake on Lan - + nymea The name of the vendor ({2062d64d-3232-433c-88bc-0d33c0ba2ba6}) nymea - + Wake On Lan The name of the ThingClass ({3c8f2447-dcd0-4882-8c09-99e579e4d24c}) Wake On Lan - + MAC address The name of the ParamType (ThingClass: wol, Type: thing, ID: {e2ba04ac-9fe1-4f9d-8152-024c27030cde}) Endereço MAC - + Wake up device The name of the ActionType ({fb9b9d87-218f-4f0d-9e16-39f8a105029a}) of ThingClass wol dispositivo de acordar