nanoleaf: Add Qt6 support

master
Simon Stürz 2025-08-08 14:55:46 +02:00
parent 47d8cb8a7b
commit 2b3d60071e
4 changed files with 47 additions and 48 deletions

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -31,8 +31,8 @@
#include "integrationpluginnanoleaf.h"
#include "plugininfo.h"
#include "network/zeroconf/zeroconfservicebrowser.h"
#include "platform/platformzeroconfcontroller.h"
#include <network/zeroconf/zeroconfservicebrowser.h>
#include <platform/platformzeroconfcontroller.h>
#include <QHash>
#include <QDebug>
@ -60,9 +60,8 @@ void IntegrationPluginNanoleaf::discoverThings(ThingDiscoveryInfo *info)
QString model = entry.txt("md");
QString firmwareVersion = entry.txt("srcvers");
if (serialNumbers.contains(serialNo)) {
if (serialNumbers.contains(serialNo))
continue; //To avoid duplicated devices
}
Thing *existingThing = myThings().findByParams(ParamList() << Param(lightPanelsThingSerialNoParamTypeId, serialNo));
if (existingThing) {
@ -199,29 +198,29 @@ void IntegrationPluginNanoleaf::executeAction(ThingActionInfo *info)
if (action.actionTypeId() == lightPanelsPowerActionTypeId) {
bool power = action.param(lightPanelsPowerActionPowerParamTypeId).value().toBool();
QUuid requestId = nanoleaf->setPower(power);
connect(info, &ThingActionInfo::aborted,[requestId, this](){m_asyncActions.remove(requestId);});
connect(info, &ThingActionInfo::aborted, this, [requestId, this](){ m_asyncActions.remove(requestId); });
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == lightPanelsBrightnessActionTypeId) {
int brightness = action.param(lightPanelsBrightnessActionBrightnessParamTypeId).value().toInt();
QUuid requestId = nanoleaf->setBrightness(brightness);
connect(info, &ThingActionInfo::aborted,[requestId, this](){m_asyncActions.remove(requestId);});
connect(info, &ThingActionInfo::aborted, this, [requestId, this](){ m_asyncActions.remove(requestId); });
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == lightPanelsColorActionTypeId) {
QColor color(action.param(lightPanelsColorActionColorParamTypeId).value().toString());
QUuid requestId = nanoleaf->setColor(color);
connect(info, &ThingActionInfo::aborted,[requestId, this](){m_asyncActions.remove(requestId);});
connect(info, &ThingActionInfo::aborted, this, [requestId, this](){ m_asyncActions.remove(requestId); });
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == lightPanelsColorTemperatureActionTypeId) {
int colorTemperature = action.param(lightPanelsColorTemperatureActionColorTemperatureParamTypeId).value().toInt();
QUuid requestId = nanoleaf->setMired(colorTemperature);
connect(info, &ThingActionInfo::aborted,[requestId, this](){m_asyncActions.remove(requestId);});
connect(info, &ThingActionInfo::aborted, this, [requestId, this](){ m_asyncActions.remove(requestId); });
m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == lightPanelsAlertActionTypeId) {
QUuid requestId = nanoleaf->identify();
connect(info, &ThingActionInfo::aborted,[requestId, this](){m_asyncActions.remove(requestId);});
connect(info, &ThingActionInfo::aborted, this, [requestId, this](){ m_asyncActions.remove(requestId); });
m_asyncActions.insert(requestId, info);
}
}

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -31,12 +31,12 @@
#ifndef INTEGRATIONPLUGINNANOLEAF_H
#define INTEGRATIONPLUGINNANOLEAF_H
#include "integrations/integrationplugin.h"
#include "nanoleaf.h"
#include <integrations/integrationplugin.h>
#include <plugintimer.h>
#include <network/networkaccessmanager.h>
#include <network/zeroconf/zeroconfservicebrowser.h>
#include "plugintimer.h"
#include "network/networkaccessmanager.h"
#include "network/zeroconf/zeroconfservicebrowser.h"
#include "nanoleaf.h"
#include <QHostAddress>
@ -66,8 +66,8 @@ public:
private:
ZeroConfServiceBrowser *m_zeroconfBrowser = nullptr;
PluginTimer *m_pluginTimer = nullptr;
QHash<ThingId, Nanoleaf*> m_nanoleafConnections;
QHash<ThingId, Nanoleaf*> m_unfinishedNanoleafConnections;
QHash<ThingId, Nanoleaf *> m_nanoleafConnections;
QHash<ThingId, Nanoleaf *> m_unfinishedNanoleafConnections;
QHash<QUuid, ThingActionInfo *> m_asyncActions;
QHash<Nanoleaf *, ThingPairingInfo *> m_unfinishedPairing;
QHash<Nanoleaf *, ThingSetupInfo *> m_asyncDeviceSetup;

View File

@ -87,7 +87,7 @@ void Nanoleaf::addUser()
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->post(request, "");
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -108,7 +108,7 @@ void Nanoleaf::addUser()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
m_authToken = data.toVariant().toMap().value("auth_token").toString();
@ -129,7 +129,7 @@ void Nanoleaf::deleteUser()
QNetworkRequest request;
request.setUrl(url);
QNetworkReply *reply = m_networkManager->deleteResource(request);
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -153,7 +153,7 @@ void Nanoleaf::getControllerInfo()
QNetworkRequest request;
request.setUrl(url);
QNetworkReply *reply = m_networkManager->get(request);
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -166,7 +166,7 @@ void Nanoleaf::getControllerInfo()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
emit connectionChanged(true);
@ -241,7 +241,7 @@ void Nanoleaf::getPower()
QNetworkRequest request;
request.setUrl(url);
QNetworkReply *reply = m_networkManager->get(request);
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -254,7 +254,7 @@ void Nanoleaf::getPower()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
bool power = data.toVariant().toMap().value("value").toBool();
@ -274,7 +274,7 @@ void Nanoleaf::getHue()
QNetworkRequest request;
request.setUrl(url);
QNetworkReply *reply = m_networkManager->get(request);
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -286,7 +286,7 @@ void Nanoleaf::getHue()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
int hue = data.toVariant().toMap().value("value").toBool();
@ -317,7 +317,7 @@ void Nanoleaf::getBrightness()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
int brightness = data.toVariant().toMap().value("value").toInt();
@ -348,7 +348,7 @@ void Nanoleaf::getSaturation()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
int brightness = data.toVariant().toMap().value("value").toInt();
@ -380,7 +380,7 @@ void Nanoleaf::getColorTemperature()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
int kelvin = data.toVariant().toMap().value("value").toInt();
@ -412,7 +412,7 @@ void Nanoleaf::getColorMode()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
emit connectionChanged(true);
@ -443,11 +443,11 @@ void Nanoleaf::registerForEvents()
request.setUrl(url);
QNetworkReply *reply = m_networkManager->get(request);
connect(reply, &QNetworkReply::readyRead, this, [reply, this] {
connect(reply, &QNetworkReply::readyRead, this, [reply] {
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
qCDebug(dcNanoleaf()) << "On event stream" << data.toJson();
@ -464,7 +464,7 @@ void Nanoleaf::registerForEvents()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
qCDebug(dcNanoleaf()) << "Event received" << data.toJson();
@ -528,7 +528,7 @@ QUuid Nanoleaf::setPower(bool power)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -570,7 +570,7 @@ QUuid Nanoleaf::setHue(int hue)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -604,7 +604,7 @@ QUuid Nanoleaf::setBrightness(int percentage)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
//qDebug(dcNanoleaf()) << "Sending request" << request.url();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -638,7 +638,7 @@ QUuid Nanoleaf::setSaturation(int percentage)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
//qDebug(dcNanoleaf()) << "Sending request" << request.url() << body.toJson();
//qCDebug(dcNanoleaf()) << "Sending request" << request.url() << body.toJson();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -680,7 +680,7 @@ QUuid Nanoleaf::setKelvin(int kelvin)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
qDebug(dcNanoleaf()) << "Sending request" << request.url() << body.toJson();
qCDebug(dcNanoleaf()) << "Sending request" << request.url() << body.toJson();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -718,7 +718,7 @@ void Nanoleaf::getEffects()
QJsonParseError error;
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
qCDebug(dcNanoleaf()) << "Recieved invalide JSON object";
return;
}
QStringList effects;
@ -774,7 +774,7 @@ QUuid Nanoleaf::setEffect(const QString &effect)
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
qDebug(dcNanoleaf()) << "Sending request" << request.url();
qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
@ -802,7 +802,7 @@ QUuid Nanoleaf::identify()
request.setUrl(url);
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
QNetworkReply *reply = m_networkManager->put(request, "");
qDebug(dcNanoleaf()) << "Sending request" << request.url();
qCDebug(dcNanoleaf()) << "Sending request" << request.url();
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
reply->deleteLater();
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();

View File

@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Copyright 2013 - 2020, nymea GmbH
* Copyright 2013 - 2025, nymea GmbH
* Contact: contact@nymea.io
*
* This file is part of nymea.
@ -37,8 +37,8 @@
#include <QHostAddress>
#include <QColor>
#include "network/networkaccessmanager.h"
#include "integrations/thing.h"
#include <network/networkaccessmanager.h>
#include <integrations/thing.h>
class Nanoleaf : public QObject
{
@ -119,11 +119,11 @@ signals:
void authenticationStatusChanged(bool authenticated);
void requestExecuted(QUuid requestId, bool success);
void controllerInfoReceived(const ControllerInfo &controllerInfo);
void controllerInfoReceived(const Nanoleaf::ControllerInfo &controllerInfo);
void authTokenRecieved(const QString &token);
void powerReceived(bool power);
void brightnessReceived(int percentage);
void colorModeReceived(ColorMode colorMode);
void colorModeReceived(Nanoleaf::ColorMode colorMode);
void hueReceived(int hue);
void saturationReceived(int percentage);
void effectListReceived(const QStringList &effects);
@ -132,7 +132,7 @@ signals:
void selectedEffectReceived(const QString &effect);
//Only supported by Canvas
void touchEventReceived(GestureID gesture);
void touchEventReceived(Nanoleaf::GestureID gesture);
};
#endif // NANOLEAF_H