fixed nanoleaf pairing and thing setup

master
bernhard.trinnes 2020-09-09 12:56:27 +02:00
parent 83becea2e8
commit 2efa44de64
3 changed files with 39 additions and 26 deletions

View File

@ -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;

View File

@ -4,22 +4,28 @@
<context>
<name>IntegrationPluginNanoleaf</name>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="96"/>
<location filename="../integrationpluginnanoleaf.cpp" line="87"/>
<source>On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing.</source>
<translation>Halten Sie auf dem Nanoleaf-Controller die Ein- / Aus-Taste 5-7 Sekunden lang gedrückt, bis die LED zu blinken beginnt.</translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="421"/>
<location filename="../integrationpluginnanoleaf.cpp" line="98"/>
<location filename="../integrationpluginnanoleaf.cpp" line="137"/>
<source>Cloud not find device.</source>
<translation>Das Gerät konnte nicht gefunden werden.</translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="413"/>
<source>Color temperature</source>
<translation>Farbtemperatur</translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="424"/>
<location filename="../integrationpluginnanoleaf.cpp" line="416"/>
<source>Hue/Saturation</source>
<translation>Farbton / Sättigung</translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="427"/>
<location filename="../integrationpluginnanoleaf.cpp" line="419"/>
<source>Effect</source>
<translation>Effekt</translation>
</message>

View File

@ -4,22 +4,28 @@
<context>
<name>IntegrationPluginNanoleaf</name>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="96"/>
<location filename="../integrationpluginnanoleaf.cpp" line="87"/>
<source>On the Nanoleaf controller, hold the on-off button for 5-7 seconds until the LED starts flashing.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="421"/>
<location filename="../integrationpluginnanoleaf.cpp" line="98"/>
<location filename="../integrationpluginnanoleaf.cpp" line="137"/>
<source>Cloud not find device.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="413"/>
<source>Color temperature</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="424"/>
<location filename="../integrationpluginnanoleaf.cpp" line="416"/>
<source>Hue/Saturation</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../integrationpluginnanoleaf.cpp" line="427"/>
<location filename="../integrationpluginnanoleaf.cpp" line="419"/>
<source>Effect</source>
<translation type="unfinished"></translation>
</message>