lifx: Add Qt6 support
This commit is contained in:
parent
6e153628c1
commit
02739277e5
@ -29,12 +29,11 @@
|
|||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "integrationpluginlifx.h"
|
#include "integrationpluginlifx.h"
|
||||||
|
|
||||||
#include "integrations/integrationplugin.h"
|
|
||||||
#include "types/param.h"
|
|
||||||
#include "plugininfo.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 <QDebug>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -31,17 +31,18 @@
|
|||||||
#ifndef INTEGRATIONPLUGINLIFX_H
|
#ifndef INTEGRATIONPLUGINLIFX_H
|
||||||
#define INTEGRATIONPLUGINLIFX_H
|
#define INTEGRATIONPLUGINLIFX_H
|
||||||
|
|
||||||
#include "integrations/integrationplugin.h"
|
#include <integrations/integrationplugin.h>
|
||||||
#include "plugintimer.h"
|
|
||||||
#include "lifxlan.h"
|
|
||||||
#include "lifxcloud.h"
|
|
||||||
|
|
||||||
#include "network/networkaccessmanager.h"
|
#include <plugintimer.h>
|
||||||
#include "network/zeroconf/zeroconfservicebrowser.h"
|
#include <network/networkaccessmanager.h>
|
||||||
#include "network/zeroconf/zeroconfserviceentry.h"
|
#include <network/zeroconf/zeroconfservicebrowser.h>
|
||||||
|
#include <network/zeroconf/zeroconfserviceentry.h>
|
||||||
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "lifxlan.h"
|
||||||
|
#include "lifxcloud.h"
|
||||||
|
|
||||||
class IntegrationPluginLifx : public IntegrationPlugin
|
class IntegrationPluginLifx : public IntegrationPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
include(../plugins.pri)
|
include(../plugins.pri)
|
||||||
|
|
||||||
QT += network
|
QT += network gui
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
integrationpluginlifx.cpp \
|
integrationpluginlifx.cpp \
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||||
*
|
*
|
||||||
* Copyright 2013 - 2020, nymea GmbH
|
* Copyright 2013 - 2025, nymea GmbH
|
||||||
* Contact: contact@nymea.io
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -83,7 +83,7 @@ void LifxCloud::listLights()
|
|||||||
QJsonDocument data; QJsonParseError error;
|
QJsonDocument data; QJsonParseError error;
|
||||||
data = QJsonDocument::fromJson(rawData, &error);
|
data = QJsonDocument::fromJson(rawData, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ void LifxCloud::listScenes()
|
|||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl("https://api.lifx.com/v1/scenes"));
|
request.setUrl(QUrl("https://api.lifx.com/v1/scenes"));
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
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);
|
QNetworkReply *reply = m_networkManager->get(request);
|
||||||
connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater);
|
connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater);
|
||||||
@ -164,7 +164,7 @@ void LifxCloud::listScenes()
|
|||||||
QJsonDocument data; QJsonParseError error;
|
QJsonDocument data; QJsonParseError error;
|
||||||
data = QJsonDocument::fromJson(rawData, &error);
|
data = QJsonDocument::fromJson(rawData, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (!data.isArray())
|
if (!data.isArray())
|
||||||
@ -213,7 +213,8 @@ int LifxCloud::activateScene(const QString &sceneId)
|
|||||||
qCWarning(dcLifx()) << "Authorization token is not set";
|
qCWarning(dcLifx()) << "Authorization token is not set";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int requestId = qrand();
|
|
||||||
|
int requestId = std::rand();
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl(QString("https://api.lifx.com/v1/scenes/scene_id:%1/activate").arg(sceneId)));
|
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";
|
qCWarning(dcLifx()) << "Authorization token is not set";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
QUrlQuery params;
|
QUrlQuery params;
|
||||||
switch (effect) {
|
switch (effect) {
|
||||||
@ -285,7 +286,7 @@ int LifxCloud::setState(const QString &selector, State state, QVariant stateValu
|
|||||||
qCWarning(dcLifx()) << "Authorization token is not set";
|
qCWarning(dcLifx()) << "Authorization token is not set";
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/%1/state").arg(selector)));
|
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/%1/state").arg(selector)));
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
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
|
* Contact: contact@nymea.io
|
||||||
*
|
*
|
||||||
* This file is part of nymea.
|
* This file is part of nymea.
|
||||||
@ -34,7 +34,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "network/networkaccessmanager.h"
|
|
||||||
|
#include <network/networkaccessmanager.h>
|
||||||
|
|
||||||
class LifxCloud : public QObject
|
class LifxCloud : public QObject
|
||||||
{
|
{
|
||||||
@ -73,13 +74,13 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct Capabilities {
|
struct Capabilities {
|
||||||
bool color;
|
bool color;
|
||||||
bool colorTemperature;
|
bool colorTemperature;
|
||||||
bool ir;
|
bool ir;
|
||||||
bool chain;
|
bool chain;
|
||||||
bool multizone;
|
bool multizone;
|
||||||
int minKelvin;
|
int minKelvin;
|
||||||
int maxKelvin;
|
int maxKelvin;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Product {
|
struct Product {
|
||||||
@ -105,6 +106,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
explicit LifxCloud(NetworkAccessManager *networkManager, QObject *parent = nullptr);
|
explicit LifxCloud(NetworkAccessManager *networkManager, QObject *parent = nullptr);
|
||||||
|
|
||||||
void setAuthorizationToken(const QByteArray &token);
|
void setAuthorizationToken(const QByteArray &token);
|
||||||
bool cloudAuthenticated();
|
bool cloudAuthenticated();
|
||||||
bool cloudConnected();
|
bool cloudConnected();
|
||||||
@ -119,7 +121,7 @@ public:
|
|||||||
|
|
||||||
int activateScene(const QString &sceneId);
|
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:
|
private:
|
||||||
NetworkAccessManager *m_networkManager = nullptr;
|
NetworkAccessManager *m_networkManager = nullptr;
|
||||||
@ -129,11 +131,12 @@ private:
|
|||||||
bool checkHttpStatusCode(QNetworkReply *reply);
|
bool checkHttpStatusCode(QNetworkReply *reply);
|
||||||
bool m_authenticated = false;
|
bool m_authenticated = false;
|
||||||
bool m_connected = false;
|
bool m_connected = false;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void connectionChanged(bool m_connected);
|
void connectionChanged(bool m_connected);
|
||||||
void authenticationChanged(bool m_authenticated);
|
void authenticationChanged(bool m_authenticated);
|
||||||
void lightsListReceived(const QList<Light> &lights);
|
void lightsListReceived(const QList<LifxCloud::Light> &lights);
|
||||||
void scenesListReceived(const QList<Scene> &scenes);
|
void scenesListReceived(const QList<LifxCloud::Scene> &scenes);
|
||||||
void requestExecuted(int requestId, bool susccess);
|
void requestExecuted(int requestId, bool susccess);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -33,13 +33,14 @@
|
|||||||
#include "extern-plugininfo.h"
|
#include "extern-plugininfo.h"
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
LifxLan::LifxLan(const QHostAddress &address, quint16 port, QObject *parent) :
|
LifxLan::LifxLan(const QHostAddress &address, quint16 port, QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
m_host(address),
|
m_host(address),
|
||||||
m_port(port)
|
m_port(port)
|
||||||
{
|
{
|
||||||
m_clientId = qrand();
|
m_clientId = std::rand();
|
||||||
|
|
||||||
m_socket = new QUdpSocket(this);
|
m_socket = new QUdpSocket(this);
|
||||||
|
|
||||||
@ -89,7 +90,7 @@ int LifxLan::setColorTemperature(uint mirad, uint msFadeTime)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(mirad)
|
Q_UNUSED(mirad)
|
||||||
Q_UNUSED(msFadeTime)
|
Q_UNUSED(msFadeTime)
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
Message message;
|
Message message;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
return requestId;
|
return requestId;
|
||||||
@ -99,7 +100,7 @@ int LifxLan::setColor(QColor color, uint msFadeTime)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(color)
|
Q_UNUSED(color)
|
||||||
Q_UNUSED(msFadeTime)
|
Q_UNUSED(msFadeTime)
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
Message message;
|
Message message;
|
||||||
//TODO create LAN message
|
//TODO create LAN message
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
@ -110,7 +111,7 @@ int LifxLan::setBrightness(uint percentage, uint msFadeTime)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(percentage)
|
Q_UNUSED(percentage)
|
||||||
Q_UNUSED(msFadeTime)
|
Q_UNUSED(msFadeTime)
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
Message message;
|
Message message;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
//TODO create LAN message
|
//TODO create LAN message
|
||||||
@ -121,7 +122,7 @@ int LifxLan::setPower(bool power, uint msFadeTime)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(power)
|
Q_UNUSED(power)
|
||||||
Q_UNUSED(msFadeTime)
|
Q_UNUSED(msFadeTime)
|
||||||
int requestId = qrand();
|
int requestId = std::rand();
|
||||||
Message message;
|
Message message;
|
||||||
sendMessage(message);
|
sendMessage(message);
|
||||||
//TODO create LAN message
|
//TODO create LAN message
|
||||||
|
|||||||
@ -36,8 +36,6 @@
|
|||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QUdpSocket>
|
#include <QUdpSocket>
|
||||||
|
|
||||||
#include "network/networkaccessmanager.h"
|
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
class LifxLan : public QObject
|
class LifxLan : public QObject
|
||||||
@ -111,19 +109,20 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct LifxProduct {
|
struct LifxProduct {
|
||||||
int pid;
|
int pid;
|
||||||
QString name;
|
QString name;
|
||||||
bool color;
|
bool color;
|
||||||
bool infrared;
|
bool infrared;
|
||||||
bool matrix;
|
bool matrix;
|
||||||
bool multizone;
|
bool multizone;
|
||||||
uint minColorTemperature;
|
uint minColorTemperature;
|
||||||
uint maxColorTemperature;
|
uint maxColorTemperature;
|
||||||
bool chain;
|
bool chain;
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit LifxLan(const QHostAddress &address, quint16 port = 56700, QObject *parent = nullptr);
|
explicit LifxLan(const QHostAddress &address, quint16 port = 56700, QObject *parent = nullptr);
|
||||||
~LifxLan();
|
~LifxLan();
|
||||||
|
|
||||||
bool enable();
|
bool enable();
|
||||||
void setHostAddress(const QHostAddress &address);
|
void setHostAddress(const QHostAddress &address);
|
||||||
void setPort(quint16 port);
|
void setPort(quint16 port);
|
||||||
@ -150,5 +149,6 @@ private slots:
|
|||||||
signals:
|
signals:
|
||||||
void connectionChanged(bool connected);
|
void connectionChanged(bool connected);
|
||||||
void requestExecuted(int requestId, bool success);
|
void requestExecuted(int requestId, bool success);
|
||||||
|
|
||||||
};
|
};
|
||||||
#endif // LIFXLAN_H
|
#endif // LIFXLAN_H
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user