From 02739277e5b1655f3e22b6dc6d62cc05c92b27ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Fri, 8 Aug 2025 14:34:53 +0200 Subject: [PATCH] lifx: Add Qt6 support --- lifx/integrationpluginlifx.cpp | 9 ++++----- lifx/integrationpluginlifx.h | 17 +++++++++-------- lifx/lifx.pro | 2 +- lifx/lifxcloud.cpp | 15 ++++++++------- lifx/lifxcloud.h | 27 +++++++++++++++------------ lifx/lifxlan.cpp | 11 ++++++----- lifx/lifxlan.h | 22 +++++++++++----------- 7 files changed, 54 insertions(+), 49 deletions(-) diff --git a/lifx/integrationpluginlifx.cpp b/lifx/integrationpluginlifx.cpp index 6f39f9e5..252be577 100644 --- a/lifx/integrationpluginlifx.cpp +++ b/lifx/integrationpluginlifx.cpp @@ -29,12 +29,11 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "integrationpluginlifx.h" - -#include "integrations/integrationplugin.h" -#include "types/param.h" #include "plugininfo.h" -#include "platform/platformzeroconfcontroller.h" -#include "network/zeroconf/zeroconfservicebrowser.h" + +#include +#include +#include #include #include diff --git a/lifx/integrationpluginlifx.h b/lifx/integrationpluginlifx.h index 2b440d5d..c19ff3cc 100644 --- a/lifx/integrationpluginlifx.h +++ b/lifx/integrationpluginlifx.h @@ -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,17 +31,18 @@ #ifndef INTEGRATIONPLUGINLIFX_H #define INTEGRATIONPLUGINLIFX_H -#include "integrations/integrationplugin.h" -#include "plugintimer.h" -#include "lifxlan.h" -#include "lifxcloud.h" +#include -#include "network/networkaccessmanager.h" -#include "network/zeroconf/zeroconfservicebrowser.h" -#include "network/zeroconf/zeroconfserviceentry.h" +#include +#include +#include +#include #include +#include "lifxlan.h" +#include "lifxcloud.h" + class IntegrationPluginLifx : public IntegrationPlugin { Q_OBJECT diff --git a/lifx/lifx.pro b/lifx/lifx.pro index 20671af6..3f07884a 100644 --- a/lifx/lifx.pro +++ b/lifx/lifx.pro @@ -1,6 +1,6 @@ include(../plugins.pri) -QT += network +QT += network gui SOURCES += \ integrationpluginlifx.cpp \ diff --git a/lifx/lifxcloud.cpp b/lifx/lifxcloud.cpp index 1aabda98..617bc115 100644 --- a/lifx/lifxcloud.cpp +++ b/lifx/lifxcloud.cpp @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -83,7 +83,7 @@ void LifxCloud::listLights() QJsonDocument data; QJsonParseError error; data = QJsonDocument::fromJson(rawData, &error); if (error.error != QJsonParseError::NoError) { - qDebug(dcLifx()) << "List lights: Received invalide JSON object" << error.errorString(); + qCDebug(dcLifx()) << "List lights: Received invalide JSON object" << error.errorString(); return; } @@ -151,7 +151,7 @@ void LifxCloud::listScenes() QNetworkRequest request; request.setUrl(QUrl("https://api.lifx.com/v1/scenes")); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); - request.setRawHeader("Authorization","Bearer "+m_authorizationToken); + request.setRawHeader("Authorization","Bearer " + m_authorizationToken); QNetworkReply *reply = m_networkManager->get(request); connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater); @@ -164,7 +164,7 @@ void LifxCloud::listScenes() QJsonDocument data; QJsonParseError error; data = QJsonDocument::fromJson(rawData, &error); if (error.error != QJsonParseError::NoError) { - qDebug(dcLifx()) << "List scenes: Received invalide JSON object" << error.errorString(); + qCDebug(dcLifx()) << "List scenes: Received invalide JSON object" << error.errorString(); return; } if (!data.isArray()) @@ -213,7 +213,8 @@ int LifxCloud::activateScene(const QString &sceneId) qCWarning(dcLifx()) << "Authorization token is not set"; return -1; } - int requestId = qrand(); + + int requestId = std::rand(); QNetworkRequest request; request.setUrl(QUrl(QString("https://api.lifx.com/v1/scenes/scene_id:%1/activate").arg(sceneId))); @@ -235,7 +236,7 @@ int LifxCloud::setEffect(const QString &lightId, LifxCloud::Effect effect, QColo qCWarning(dcLifx()) << "Authorization token is not set"; return -1; } - int requestId = qrand(); + int requestId = std::rand(); QNetworkRequest request; QUrlQuery params; switch (effect) { @@ -285,7 +286,7 @@ int LifxCloud::setState(const QString &selector, State state, QVariant stateValu qCWarning(dcLifx()) << "Authorization token is not set"; return -1; } - int requestId = qrand(); + int requestId = std::rand(); QNetworkRequest request; request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/%1/state").arg(selector))); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); diff --git a/lifx/lifxcloud.h b/lifx/lifxcloud.h index df95369b..752a8d73 100644 --- a/lifx/lifxcloud.h +++ b/lifx/lifxcloud.h @@ -1,6 +1,6 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* Copyright 2013 - 2020, nymea GmbH +* Copyright 2013 - 2025, nymea GmbH * Contact: contact@nymea.io * * This file is part of nymea. @@ -34,7 +34,8 @@ #include #include #include -#include "network/networkaccessmanager.h" + +#include class LifxCloud : public QObject { @@ -73,13 +74,13 @@ public: }; struct Capabilities { - bool color; - bool colorTemperature; - bool ir; - bool chain; - bool multizone; - int minKelvin; - int maxKelvin; + bool color; + bool colorTemperature; + bool ir; + bool chain; + bool multizone; + int minKelvin; + int maxKelvin; }; struct Product { @@ -105,6 +106,7 @@ public: }; explicit LifxCloud(NetworkAccessManager *networkManager, QObject *parent = nullptr); + void setAuthorizationToken(const QByteArray &token); bool cloudAuthenticated(); bool cloudConnected(); @@ -119,7 +121,7 @@ public: int activateScene(const QString &sceneId); - int setEffect(const QString &lightId, Effect effect, QColor color = "#FFFFFF"); + int setEffect(const QString &lightId, Effect effect, QColor color = QColor("#FFFFFF")); private: NetworkAccessManager *m_networkManager = nullptr; @@ -129,11 +131,12 @@ private: bool checkHttpStatusCode(QNetworkReply *reply); bool m_authenticated = false; bool m_connected = false; + signals: void connectionChanged(bool m_connected); void authenticationChanged(bool m_authenticated); - void lightsListReceived(const QList &lights); - void scenesListReceived(const QList &scenes); + void lightsListReceived(const QList &lights); + void scenesListReceived(const QList &scenes); void requestExecuted(int requestId, bool susccess); }; diff --git a/lifx/lifxlan.cpp b/lifx/lifxlan.cpp index 2c707627..e299cc6b 100644 --- a/lifx/lifxlan.cpp +++ b/lifx/lifxlan.cpp @@ -33,13 +33,14 @@ #include "extern-plugininfo.h" #include +#include LifxLan::LifxLan(const QHostAddress &address, quint16 port, QObject *parent) : QObject(parent), m_host(address), m_port(port) { - m_clientId = qrand(); + m_clientId = std::rand(); m_socket = new QUdpSocket(this); @@ -89,7 +90,7 @@ int LifxLan::setColorTemperature(uint mirad, uint msFadeTime) { Q_UNUSED(mirad) Q_UNUSED(msFadeTime) - int requestId = qrand(); + int requestId = std::rand(); Message message; sendMessage(message); return requestId; @@ -99,7 +100,7 @@ int LifxLan::setColor(QColor color, uint msFadeTime) { Q_UNUSED(color) Q_UNUSED(msFadeTime) - int requestId = qrand(); + int requestId = std::rand(); Message message; //TODO create LAN message sendMessage(message); @@ -110,7 +111,7 @@ int LifxLan::setBrightness(uint percentage, uint msFadeTime) { Q_UNUSED(percentage) Q_UNUSED(msFadeTime) - int requestId = qrand(); + int requestId = std::rand(); Message message; sendMessage(message); //TODO create LAN message @@ -121,7 +122,7 @@ int LifxLan::setPower(bool power, uint msFadeTime) { Q_UNUSED(power) Q_UNUSED(msFadeTime) - int requestId = qrand(); + int requestId = std::rand(); Message message; sendMessage(message); //TODO create LAN message diff --git a/lifx/lifxlan.h b/lifx/lifxlan.h index e15dea84..e029824b 100644 --- a/lifx/lifxlan.h +++ b/lifx/lifxlan.h @@ -36,8 +36,6 @@ #include #include -#include "network/networkaccessmanager.h" - #include class LifxLan : public QObject @@ -111,19 +109,20 @@ public: }; struct LifxProduct { - int pid; - QString name; - bool color; - bool infrared; - bool matrix; - bool multizone; - uint minColorTemperature; - uint maxColorTemperature; - bool chain; + int pid; + QString name; + bool color; + bool infrared; + bool matrix; + bool multizone; + uint minColorTemperature; + uint maxColorTemperature; + bool chain; }; explicit LifxLan(const QHostAddress &address, quint16 port = 56700, QObject *parent = nullptr); ~LifxLan(); + bool enable(); void setHostAddress(const QHostAddress &address); void setPort(quint16 port); @@ -150,5 +149,6 @@ private slots: signals: void connectionChanged(bool connected); void requestExecuted(int requestId, bool success); + }; #endif // LIFXLAN_H