diff --git a/nanoleaf/integrationpluginnanoleaf.cpp b/nanoleaf/integrationpluginnanoleaf.cpp index 46addcf9..8410c959 100644 --- a/nanoleaf/integrationpluginnanoleaf.cpp +++ b/nanoleaf/integrationpluginnanoleaf.cpp @@ -52,22 +52,14 @@ 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; - 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 } @@ -80,8 +72,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 +91,15 @@ 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()); + 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); m_unfinishedPairing.insert(nanoleaf, info); @@ -116,6 +114,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 +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(thing->paramValue(lightPanelsThingAddressParamTypeId).toString()); - int port = thing->paramValue(lightPanelsThingPortParamTypeId).toInt(); + 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,6 +271,33 @@ Nanoleaf *IntegrationPluginNanoleaf::createNanoleafConnection(const QHostAddress return nanoleaf; } +QHostAddress IntegrationPluginNanoleaf::getHostAddress(const QString &serialNumber) +{ + ZeroConfServiceEntry entry; + foreach (const ZeroConfServiceEntry &e, m_zeroconfBrowser->serviceEntries()) { + QString entrySerialNo = e.txt("id"); + + 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 = e.txt("id"); + if (serialNumber == entrySerialNo) { + entry = e; + break; + } + } + return entry.port(); +} + void IntegrationPluginNanoleaf::onAuthTokenReceived(const QString &token) { Nanoleaf *nanoleaf = static_cast(sender()); @@ -316,6 +351,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) 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 += \ 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..10c66dff --- /dev/null +++ b/nanoleaf/translations/360867ec-1594-498d-8182-fbab1fe17489-de.ts @@ -0,0 +1,216 @@ + + + + + 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 + + + + 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..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 @@ -27,21 +33,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 +51,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 +69,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 +84,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 +102,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 +117,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 +150,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 +162,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 +177,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