lifx: Add Qt6 support
This commit is contained in:
parent
6e153628c1
commit
02739277e5
@ -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 <types/param.h>
|
||||
#include <platform/platformzeroconfcontroller.h>
|
||||
#include <network/zeroconf/zeroconfservicebrowser.h>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QColor>
|
||||
|
||||
@ -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 <integrations/integrationplugin.h>
|
||||
|
||||
#include "network/networkaccessmanager.h"
|
||||
#include "network/zeroconf/zeroconfservicebrowser.h"
|
||||
#include "network/zeroconf/zeroconfserviceentry.h"
|
||||
#include <plugintimer.h>
|
||||
#include <network/networkaccessmanager.h>
|
||||
#include <network/zeroconf/zeroconfservicebrowser.h>
|
||||
#include <network/zeroconf/zeroconfserviceentry.h>
|
||||
|
||||
#include <QTimer>
|
||||
|
||||
#include "lifxlan.h"
|
||||
#include "lifxcloud.h"
|
||||
|
||||
class IntegrationPluginLifx : public IntegrationPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
include(../plugins.pri)
|
||||
|
||||
QT += network
|
||||
QT += network gui
|
||||
|
||||
SOURCES += \
|
||||
integrationpluginlifx.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");
|
||||
|
||||
@ -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 <QObject>
|
||||
#include <QColor>
|
||||
#include <QTimer>
|
||||
#include "network/networkaccessmanager.h"
|
||||
|
||||
#include <network/networkaccessmanager.h>
|
||||
|
||||
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<Light> &lights);
|
||||
void scenesListReceived(const QList<Scene> &scenes);
|
||||
void lightsListReceived(const QList<LifxCloud::Light> &lights);
|
||||
void scenesListReceived(const QList<LifxCloud::Scene> &scenes);
|
||||
void requestExecuted(int requestId, bool susccess);
|
||||
};
|
||||
|
||||
|
||||
@ -33,13 +33,14 @@
|
||||
#include "extern-plugininfo.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QVariant>
|
||||
|
||||
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
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
#include <QHostAddress>
|
||||
#include <QUdpSocket>
|
||||
|
||||
#include "network/networkaccessmanager.h"
|
||||
|
||||
#include <QColor>
|
||||
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user