From 314fa560b8bccc1397bda9cc512fcb316d37c975 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 1 Jul 2020 12:40:40 +0200 Subject: [PATCH 1/5] Nanoleaf: auto rediscovery --- nanoleaf/integrationpluginnanoleaf.cpp | 55 ++++++++++++++++++++++--- nanoleaf/integrationpluginnanoleaf.h | 2 + nanoleaf/integrationpluginnanoleaf.json | 13 ------ nanoleaf/nanoleaf.pro | 2 - 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/nanoleaf/integrationpluginnanoleaf.cpp b/nanoleaf/integrationpluginnanoleaf.cpp index 46addcf9..e00659c2 100644 --- a/nanoleaf/integrationpluginnanoleaf.cpp +++ b/nanoleaf/integrationpluginnanoleaf.cpp @@ -52,7 +52,8 @@ void IntegrationPluginNanoleaf::discoverThings(ThingDiscoveryInfo *info) QStringList serialNumbers; foreach (const ZeroConfServiceEntry &entry, m_zeroconfBrowser->serviceEntries()) { - ThingDescriptor descriptor(lightPanelsThingClassId, entry.name(), entry.hostAddress().toString()); + QHostAddress address = QHostAddress(entry.hostAddress().toString()); + ThingDescriptor descriptor(lightPanelsThingClassId, entry.name(), address.toString()); ParamList params; QString serialNo; @@ -80,8 +81,6 @@ void IntegrationPluginNanoleaf::discoverThings(ThingDiscoveryInfo *info) serialNumbers.append(serialNo); qCDebug(dcNanoleaf()) << "Have device" << entry.name() << serialNo << model << firmwareVersion; - params << Param(lightPanelsThingAddressParamTypeId, entry.hostAddress().toString()); - params << Param(lightPanelsThingPortParamTypeId, entry.port()); params << Param(lightPanelsThingModelParamTypeId, model); params << Param(lightPanelsThingSerialNoParamTypeId, serialNo); params << Param(lightPanelsThingFirmwareVersionParamTypeId, firmwareVersion); @@ -101,7 +100,9 @@ void IntegrationPluginNanoleaf::confirmPairing(ThingPairingInfo *info, const QSt { Q_UNUSED(username) Q_UNUSED(secret) - Nanoleaf *nanoleaf = createNanoleafConnection(QHostAddress(info->params().paramValue(lightPanelsThingAddressParamTypeId).toString()), info->params().paramValue(lightPanelsThingPortParamTypeId).toInt()); + QHostAddress address = getHostAddress(info->params().paramValue(lightPanelsThingSerialNoParamTypeId).toString()); + uint port = getPort(info->params().paramValue(lightPanelsThingSerialNoParamTypeId).toString()); + Nanoleaf *nanoleaf = createNanoleafConnection(address, port); nanoleaf->addUser(); //push button pairing m_unfinishedNanoleafConnections.insert(info->thingId(), nanoleaf); m_unfinishedPairing.insert(nanoleaf, info); @@ -116,6 +117,10 @@ void IntegrationPluginNanoleaf::setupThing(ThingSetupInfo *info) { Thing *thing = info->thing(); if(thing->thingClassId() == lightPanelsThingClassId) { + + QString thingSerialNo = thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString(); + qCDebug(dcNanoleaf()) << "Setting up Nanoleaf light panel with serial number:" << thingSerialNo; + pluginStorage()->beginGroup(thing->id().toString()); QString token = pluginStorage()->value("authToken").toString(); pluginStorage()->endGroup(); @@ -128,8 +133,8 @@ void IntegrationPluginNanoleaf::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorNoError); } else { // This setupDevice is called after a (re)start, with an already added thing - QHostAddress address(thing->paramValue(lightPanelsThingAddressParamTypeId).toString()); - int port = thing->paramValue(lightPanelsThingPortParamTypeId).toInt(); + QHostAddress address = getHostAddress(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString()); + int port = getPort(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString()); nanoleaf = createNanoleafConnection(address, port); nanoleaf->setAuthToken(token); nanoleaf->getControllerInfo(); //This is just to check if the thing is available @@ -263,6 +268,44 @@ Nanoleaf *IntegrationPluginNanoleaf::createNanoleafConnection(const QHostAddress return nanoleaf; } +QHostAddress IntegrationPluginNanoleaf::getHostAddress(const QString &serialNumber) +{ + ZeroConfServiceEntry entry; + foreach (const ZeroConfServiceEntry &e, m_zeroconfBrowser->serviceEntries()) { + QString entrySerialNo; + foreach (QString value, entry.txt()) { + if (value.contains("id=")) { + entrySerialNo = value.split("=").last(); + break; + } + } + if (serialNumber == entrySerialNo) { + entry = e; + break; + } + } + return QHostAddress(entry.hostAddress()); +} + +uint IntegrationPluginNanoleaf::getPort(const QString &serialNumber) +{ + ZeroConfServiceEntry entry; + foreach (const ZeroConfServiceEntry &e, m_zeroconfBrowser->serviceEntries()) { + QString entrySerialNo; + foreach (QString value, entry.txt()) { + if (value.contains("id=")) { + entrySerialNo = value.split("=").last(); + break; + } + } + if (serialNumber == entrySerialNo) { + entry = e; + break; + } + } + return entry.port(); +} + void IntegrationPluginNanoleaf::onAuthTokenReceived(const QString &token) { Nanoleaf *nanoleaf = static_cast(sender()); diff --git a/nanoleaf/integrationpluginnanoleaf.h b/nanoleaf/integrationpluginnanoleaf.h index c0a6cfb7..017ed2da 100644 --- a/nanoleaf/integrationpluginnanoleaf.h +++ b/nanoleaf/integrationpluginnanoleaf.h @@ -76,6 +76,8 @@ private: QHash m_asyncBrowserItem; Nanoleaf *createNanoleafConnection(const QHostAddress &address, int port); + QHostAddress getHostAddress(const QString &serialNumber); + uint getPort(const QString &serialNumber); public slots: void onAuthTokenReceived(const QString &token); diff --git a/nanoleaf/integrationpluginnanoleaf.json b/nanoleaf/integrationpluginnanoleaf.json index 38048e66..eaeee40a 100644 --- a/nanoleaf/integrationpluginnanoleaf.json +++ b/nanoleaf/integrationpluginnanoleaf.json @@ -17,19 +17,6 @@ "setupMethod": "pushButton", "browsable": true, "paramTypes": [ - { - "id": "ff57079f-d5ab-4511-8a5c-0726e7b82af6", - "name": "address", - "displayName": "Address", - "type" : "QString" - }, - { - "id": "ba4fd45b-990d-480a-859d-fff7ffba3ba4", - "name": "port", - "displayName": "Port", - "type" : "int", - "readOnly": true - }, { "id": "353d3c71-0ad2-40d5-99f6-cc305e2073f1", "name": "model", diff --git a/nanoleaf/nanoleaf.pro b/nanoleaf/nanoleaf.pro index 3a22fb34..90165867 100644 --- a/nanoleaf/nanoleaf.pro +++ b/nanoleaf/nanoleaf.pro @@ -1,7 +1,5 @@ include(../plugins.pri) -TARGET = $$qtLibraryTarget(nymea_integrationpluginnanoleaf) - QT += network SOURCES += \ From c1055991df5f72277612b06bbbc5addff34d1865 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 1 Jul 2020 12:46:21 +0200 Subject: [PATCH 2/5] Nanoleaf: auto rediscovery --- nanoleaf/integrationpluginnanoleaf.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nanoleaf/integrationpluginnanoleaf.cpp b/nanoleaf/integrationpluginnanoleaf.cpp index e00659c2..159e626f 100644 --- a/nanoleaf/integrationpluginnanoleaf.cpp +++ b/nanoleaf/integrationpluginnanoleaf.cpp @@ -359,6 +359,15 @@ void IntegrationPluginNanoleaf::onConnectionChanged(bool connected) if (!thing) return; thing->setStateValue(lightPanelsConnectedStateTypeId, connected); + if (!connected) { + QTimer::singleShot(3000, this, [nanoleaf, thing, connected, this] { + if (!connected) { //If after 3 seconds it is still not connected + nanoleaf->setIpAddress(getHostAddress(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString())); + nanoleaf->setPort(getPort(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString())); + nanoleaf->getControllerInfo(); //Test connection + } + }); + } } void IntegrationPluginNanoleaf::onControllerInfoReceived(const Nanoleaf::ControllerInfo &controllerInfo) From 5306e6274db50b5ea085675a42c63ec097471116 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 1 Jul 2020 12:54:23 +0200 Subject: [PATCH 3/5] added german translation --- ...360867ec-1594-498d-8182-fbab1fe17489-de.ts | 210 ++++++++++++++++++ ...867ec-1594-498d-8182-fbab1fe17489-en_US.ts | 92 ++++---- 2 files changed, 250 insertions(+), 52 deletions(-) create mode 100644 nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts diff --git a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts new file mode 100644 index 00000000..07aaac4e --- /dev/null +++ b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts @@ -0,0 +1,210 @@ + + + + + IntegrationPluginNanoleaf + + + On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing. + Halten Sie auf dem Nanoleaf-Controller die Ein- / Aus-Taste 5-7 Sekunden lang gedrückt, bis die LED zu blinken beginnt. + + + + Color temperature + Farbtemperatur + + + + Hue/Saturation + Farbton / Sättigung + + + + Effect + Effekt + + + + Nanoleaf + + + Alert + The name of the ActionType ({47a6a1a1-fb90-4f24-be8c-b4dba0aaaa84}) of ThingClass lightPanels + Alarm + + + + + + Brightness + The name of the ParamType (ThingClass: lightPanels, ActionType: brightness, ID: {4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) +---------- +The name of the ParamType (ThingClass: lightPanels, EventType: brightness, ID: {4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) +---------- +The name of the StateType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass lightPanels + Helligkeit + + + + Brightness changed + The name of the EventType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass lightPanels + Helligkeit geändert + + + + + + Color + The name of the ParamType (ThingClass: lightPanels, ActionType: color, ID: {d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) +---------- +The name of the ParamType (ThingClass: lightPanels, EventType: color, ID: {d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) +---------- +The name of the StateType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass lightPanels + Farbe + + + + Color changed + The name of the EventType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass lightPanels + Farbe geändert + + + + + Color mode + The name of the ParamType (ThingClass: lightPanels, EventType: colorMode, ID: {bdd2ea1e-9ef9-4967-9678-2c601b826199}) +---------- +The name of the StateType ({bdd2ea1e-9ef9-4967-9678-2c601b826199}) of ThingClass lightPanels + Farbmodus + + + + Color mode changed + The name of the EventType ({bdd2ea1e-9ef9-4967-9678-2c601b826199}) of ThingClass lightPanels + Farbmodus geändert + + + + + + Color temperature + The name of the ParamType (ThingClass: lightPanels, ActionType: colorTemperature, ID: {41248127-844b-40be-87e6-38aee48b6687}) +---------- +The name of the ParamType (ThingClass: lightPanels, EventType: colorTemperature, ID: {41248127-844b-40be-87e6-38aee48b6687}) +---------- +The name of the StateType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass lightPanels + Farbtemperatur + + + + Color temperature changed + The name of the EventType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass lightPanels + Farbtemperatur geändert + + + + + Effect name + The name of the ParamType (ThingClass: lightPanels, EventType: effectName, ID: {57f9831e-1b98-41c1-a21c-6073ff327237}) +---------- +The name of the StateType ({57f9831e-1b98-41c1-a21c-6073ff327237}) of ThingClass lightPanels + Effektname + + + + Effect name changed + The name of the EventType ({57f9831e-1b98-41c1-a21c-6073ff327237}) of ThingClass lightPanels + Effektname geändert + + + + Firmware version + The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {1b85eebe-3b1a-49a9-bddb-2175d6599b95}) + Firmwareversion + + + + Light panels + The name of the ThingClass ({d44ee383-9fa5-4751-babd-1129ac20896a}) + Lightpaneele + + + + Model + The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {353d3c71-0ad2-40d5-99f6-cc305e2073f1}) + Modell + + + + + Nanoleaf + The name of the vendor ({3d7fdaa6-7896-419b-8be3-c90c42bcac7f}) +---------- +The name of the plugin Nanoleaf ({360867ec-1594-498d-8182-fbab1fe17489}) + Nanoleaf + + + + + + Power + The name of the ParamType (ThingClass: lightPanels, ActionType: power, ID: {44bee9ec-513d-4834-991a-ee9ae69d9f2a}) +---------- +The name of the ParamType (ThingClass: lightPanels, EventType: power, ID: {44bee9ec-513d-4834-991a-ee9ae69d9f2a}) +---------- +The name of the StateType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass lightPanels + Eingeschalten + + + + Power changed + The name of the EventType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass lightPanels + Eingeschalten geändert + + + + + Reachable + The name of the ParamType (ThingClass: lightPanels, EventType: connected, ID: {a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) +---------- +The name of the StateType ({a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) of ThingClass lightPanels + ERreichbar + + + + Reachable changed + The name of the EventType ({a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) of ThingClass lightPanels + Erriechbar geändert + + + + Serial number + The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {18be4a5f-e2c2-4070-bc3e-ea9fe64f2276}) + Seriennummer + + + + Set brightness + The name of the ActionType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass lightPanels + Setze Helligkeit + + + + Set color + The name of the ActionType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass lightPanels + Setze Farbe + + + + Set color temperature + The name of the ActionType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass lightPanels + Setze Farbtemperatur + + + + Set power + The name of the ActionType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass lightPanels + Setze Eingeschalten + + + diff --git a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts index 3d3f4b00..29ff6d67 100644 --- a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts +++ b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts @@ -4,22 +4,22 @@ IntegrationPluginNanoleaf - + On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing. - + Color temperature - + Hue/Saturation - + Effect @@ -27,21 +27,15 @@ Nanoleaf - - Address - The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {ff57079f-d5ab-4511-8a5c-0726e7b82af6}) - - - - + Alert The name of the ActionType ({47a6a1a1-fb90-4f24-be8c-b4dba0aaaa84}) of ThingClass lightPanels - - - + + + Brightness The name of the ParamType (ThingClass: lightPanels, ActionType: brightness, ID: {4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) ---------- @@ -51,15 +45,15 @@ The name of the StateType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass - + Brightness changed The name of the EventType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass lightPanels - - - + + + Color The name of the ParamType (ThingClass: lightPanels, ActionType: color, ID: {d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) ---------- @@ -69,14 +63,14 @@ The name of the StateType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass - + Color changed The name of the EventType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass lightPanels - - + + Color mode The name of the ParamType (ThingClass: lightPanels, EventType: colorMode, ID: {bdd2ea1e-9ef9-4967-9678-2c601b826199}) ---------- @@ -84,15 +78,15 @@ The name of the StateType ({bdd2ea1e-9ef9-4967-9678-2c601b826199}) of ThingClass - + Color mode changed The name of the EventType ({bdd2ea1e-9ef9-4967-9678-2c601b826199}) of ThingClass lightPanels - - - + + + Color temperature The name of the ParamType (ThingClass: lightPanels, ActionType: colorTemperature, ID: {41248127-844b-40be-87e6-38aee48b6687}) ---------- @@ -102,14 +96,14 @@ The name of the StateType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass - + Color temperature changed The name of the EventType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass lightPanels - - + + Effect name The name of the ParamType (ThingClass: lightPanels, EventType: effectName, ID: {57f9831e-1b98-41c1-a21c-6073ff327237}) ---------- @@ -117,32 +111,32 @@ The name of the StateType ({57f9831e-1b98-41c1-a21c-6073ff327237}) of ThingClass - + Effect name changed The name of the EventType ({57f9831e-1b98-41c1-a21c-6073ff327237}) of ThingClass lightPanels - + Firmware version The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {1b85eebe-3b1a-49a9-bddb-2175d6599b95}) - + Light panels The name of the ThingClass ({d44ee383-9fa5-4751-babd-1129ac20896a}) - + Model The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {353d3c71-0ad2-40d5-99f6-cc305e2073f1}) - - + + Nanoleaf The name of the vendor ({3d7fdaa6-7896-419b-8be3-c90c42bcac7f}) ---------- @@ -150,15 +144,9 @@ The name of the plugin Nanoleaf ({360867ec-1594-498d-8182-fbab1fe17489}) - - Port - The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {ba4fd45b-990d-480a-859d-fff7ffba3ba4}) - - - - - - + + + Power The name of the ParamType (ThingClass: lightPanels, ActionType: power, ID: {44bee9ec-513d-4834-991a-ee9ae69d9f2a}) ---------- @@ -168,14 +156,14 @@ The name of the StateType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass - + Power changed The name of the EventType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass lightPanels - - + + Reachable The name of the ParamType (ThingClass: lightPanels, EventType: connected, ID: {a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) ---------- @@ -183,37 +171,37 @@ The name of the StateType ({a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) of ThingClass - + Reachable changed The name of the EventType ({a3102107-a825-4ec8-a9ec-b2c2a9fb5c89}) of ThingClass lightPanels - + Serial number The name of the ParamType (ThingClass: lightPanels, Type: thing, ID: {18be4a5f-e2c2-4070-bc3e-ea9fe64f2276}) - + Set brightness The name of the ActionType ({4e5d6460-d42e-4b7c-a8f3-6e953451c1ef}) of ThingClass lightPanels - + Set color The name of the ActionType ({d4a52cdc-93b2-44fc-a36c-ae65f1d98f2e}) of ThingClass lightPanels - + Set color temperature The name of the ActionType ({41248127-844b-40be-87e6-38aee48b6687}) of ThingClass lightPanels - + Set power The name of the ActionType ({44bee9ec-513d-4834-991a-ee9ae69d9f2a}) of ThingClass lightPanels From 83becea2e8a5a22aa044dac7370e299cf3b210be Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 26 Aug 2020 15:49:16 +0200 Subject: [PATCH 4/5] simplified zeroconf txt parsing --- nanoleaf/integrationpluginnanoleaf.cpp | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/nanoleaf/integrationpluginnanoleaf.cpp b/nanoleaf/integrationpluginnanoleaf.cpp index 159e626f..6ac7cf19 100644 --- a/nanoleaf/integrationpluginnanoleaf.cpp +++ b/nanoleaf/integrationpluginnanoleaf.cpp @@ -56,19 +56,10 @@ void IntegrationPluginNanoleaf::discoverThings(ThingDiscoveryInfo *info) ThingDescriptor descriptor(lightPanelsThingClassId, entry.name(), address.toString()); ParamList params; - QString serialNo; - QString model; - QString firmwareVersion; + QString serialNo = entry.txt("id"); + QString model = entry.txt("md"); + QString firmwareVersion = entry.txt("srcvers"); - foreach (QString value, entry.txt()) { - if (value.contains("id=")) { - serialNo = value.split("=").last(); - } else if (value.contains("md=")) { - model = value.split("=").last(); - } else if (value.contains("srcvers=")) { - firmwareVersion = value.split("=").last(); - } - } if (serialNumbers.contains(serialNo)) { continue; //To avoid duplicated devices } From 2efa44de640bdbf9fbf516e65b6db32cd6314738 Mon Sep 17 00:00:00 2001 From: "bernhard.trinnes" Date: Wed, 9 Sep 2020 12:56:27 +0200 Subject: [PATCH 5/5] fixed nanoleaf pairing and thing setup --- nanoleaf/integrationpluginnanoleaf.cpp | 37 ++++++++++--------- ...360867ec-1594-498d-8182-fbab1fe17489-de.ts | 14 +++++-- ...867ec-1594-498d-8182-fbab1fe17489-en_US.ts | 14 +++++-- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/nanoleaf/integrationpluginnanoleaf.cpp b/nanoleaf/integrationpluginnanoleaf.cpp index 6ac7cf19..8410c959 100644 --- a/nanoleaf/integrationpluginnanoleaf.cpp +++ b/nanoleaf/integrationpluginnanoleaf.cpp @@ -91,8 +91,14 @@ void IntegrationPluginNanoleaf::confirmPairing(ThingPairingInfo *info, const QSt { Q_UNUSED(username) Q_UNUSED(secret) - QHostAddress address = getHostAddress(info->params().paramValue(lightPanelsThingSerialNoParamTypeId).toString()); - uint port = getPort(info->params().paramValue(lightPanelsThingSerialNoParamTypeId).toString()); + QString serialNumber = info->params().paramValue(lightPanelsThingSerialNoParamTypeId).toString(); + QHostAddress address = getHostAddress(serialNumber); + if (address.isNull()) { + qCWarning(dcNanoleaf()) << "Could not find any device with serial number" << serialNumber; + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Cloud not find device.")); + } + uint port = getPort(serialNumber); + qCDebug(dcNanoleaf()) << "ConfirmPairing: Creating Nanoleaf connection with address" << address << "and port" << port; Nanoleaf *nanoleaf = createNanoleafConnection(address, port); nanoleaf->addUser(); //push button pairing m_unfinishedNanoleafConnections.insert(info->thingId(), nanoleaf); @@ -124,8 +130,14 @@ void IntegrationPluginNanoleaf::setupThing(ThingSetupInfo *info) return info->finish(Thing::ThingErrorNoError); } else { // This setupDevice is called after a (re)start, with an already added thing - QHostAddress address = getHostAddress(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString()); - int port = getPort(thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString()); + QString serialNumber = thing->paramValue(lightPanelsThingSerialNoParamTypeId).toString(); + QHostAddress address = getHostAddress(serialNumber); + if (address.isNull()) { + qCWarning(dcNanoleaf()) << "Could not find any device with serial number" << serialNumber; + return info->finish(Thing::ThingErrorHardwareNotAvailable, QT_TR_NOOP("Cloud not find device.")); + } + int port = getPort(serialNumber); + qCDebug(dcNanoleaf()) << "SetupThing: Creating Nanoleaf connection with address" << address << "and port" << port; nanoleaf = createNanoleafConnection(address, port); nanoleaf->setAuthToken(token); nanoleaf->getControllerInfo(); //This is just to check if the thing is available @@ -263,13 +275,8 @@ QHostAddress IntegrationPluginNanoleaf::getHostAddress(const QString &serialNumb { ZeroConfServiceEntry entry; foreach (const ZeroConfServiceEntry &e, m_zeroconfBrowser->serviceEntries()) { - QString entrySerialNo; - foreach (QString value, entry.txt()) { - if (value.contains("id=")) { - entrySerialNo = value.split("=").last(); - break; - } - } + QString entrySerialNo = e.txt("id"); + if (serialNumber == entrySerialNo) { entry = e; break; @@ -282,13 +289,7 @@ uint IntegrationPluginNanoleaf::getPort(const QString &serialNumber) { ZeroConfServiceEntry entry; foreach (const ZeroConfServiceEntry &e, m_zeroconfBrowser->serviceEntries()) { - QString entrySerialNo; - foreach (QString value, entry.txt()) { - if (value.contains("id=")) { - entrySerialNo = value.split("=").last(); - break; - } - } + QString entrySerialNo = e.txt("id"); if (serialNumber == entrySerialNo) { entry = e; break; diff --git a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts index 07aaac4e..10c66dff 100644 --- a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts +++ b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts @@ -4,22 +4,28 @@ IntegrationPluginNanoleaf - + On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing. Halten Sie auf dem Nanoleaf-Controller die Ein- / Aus-Taste 5-7 Sekunden lang gedrückt, bis die LED zu blinken beginnt. - + + + Cloud not find device. + Das Gerät konnte nicht gefunden werden. + + + Color temperature Farbtemperatur - + Hue/Saturation Farbton / Sättigung - + Effect Effekt diff --git a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts index 29ff6d67..3ba518d8 100644 --- a/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts +++ b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-en_US.ts @@ -4,22 +4,28 @@ IntegrationPluginNanoleaf - + On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing. - + + + Cloud not find device. + + + + Color temperature - + Hue/Saturation - + Effect