tado: Add Qt6 support
parent
40a67689a5
commit
51ccbc0ca4
|
|
@ -29,9 +29,10 @@
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||||
|
|
||||||
#include "integrationplugintado.h"
|
#include "integrationplugintado.h"
|
||||||
#include "integrations/thing.h"
|
|
||||||
#include "plugininfo.h"
|
#include "plugininfo.h"
|
||||||
#include "network/networkaccessmanager.h"
|
|
||||||
|
#include <integrations/thing.h>
|
||||||
|
#include <network/networkaccessmanager.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QUrlQuery>
|
#include <QUrlQuery>
|
||||||
|
|
|
||||||
|
|
@ -31,16 +31,16 @@
|
||||||
#ifndef INTEGRATIONPLUGINTADO_H
|
#ifndef INTEGRATIONPLUGINTADO_H
|
||||||
#define INTEGRATIONPLUGINTADO_H
|
#define INTEGRATIONPLUGINTADO_H
|
||||||
|
|
||||||
#include "tado.h"
|
|
||||||
#include "extern-plugininfo.h"
|
|
||||||
|
|
||||||
#include <plugintimer.h>
|
|
||||||
#include <integrations/integrationplugin.h>
|
#include <integrations/integrationplugin.h>
|
||||||
|
#include <plugintimer.h>
|
||||||
#include <network/oauth2.h>
|
#include <network/oauth2.h>
|
||||||
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
#include "extern-plugininfo.h"
|
||||||
|
#include "tado.h"
|
||||||
|
|
||||||
class IntegrationPluginTado : public IntegrationPlugin
|
class IntegrationPluginTado : public IntegrationPlugin
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ void Tado::getLoginUrl()
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Token: Received invalid JSON object:" << data;
|
qCDebug(dcTado()) << "Get Token: Received invalid JSON object:" << data;
|
||||||
emit getLoginUrlFinished(false);
|
emit getLoginUrlFinished(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -205,7 +205,7 @@ void Tado::getAccessToken()
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get access token received invalid JSON object:" << data;
|
qCDebug(dcTado()) << "Get access token received invalid JSON object:" << data;
|
||||||
emit getLoginUrlFinished(false);
|
emit getLoginUrlFinished(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -247,7 +247,7 @@ void Tado::getHomes()
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
QNetworkReply *reply = m_networkManager->get(request);
|
||||||
//qDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
//qCDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
||||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
|
|
||||||
|
|
@ -271,7 +271,7 @@ void Tado::getHomes()
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Homes: Recieved invalid JSON object";
|
qCDebug(dcTado()) << "Get Homes: Recieved invalid JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -315,7 +315,7 @@ void Tado::getZones(const QString &homeId)
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
QNetworkReply *reply = m_networkManager->get(request);
|
||||||
//qDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
//qCDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
||||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
connect(reply, &QNetworkReply::finished, this, [reply, homeId, this] {
|
connect(reply, &QNetworkReply::finished, this, [reply, homeId, this] {
|
||||||
|
|
||||||
|
|
@ -338,7 +338,7 @@ void Tado::getZones(const QString &homeId)
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
qCDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QList<Zone> zones;
|
QList<Zone> zones;
|
||||||
|
|
@ -372,7 +372,7 @@ void Tado::getZoneState(const QString &homeId, const QString &zoneId)
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
request.setRawHeader("Authorization", "Bearer " + m_accessToken.toLocal8Bit());
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
QNetworkReply *reply = m_networkManager->get(request);
|
||||||
//qDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
//qCDebug(dcTado()) << "Sending request" << request.url() << request.rawHeaderList();
|
||||||
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
connect(reply, &QNetworkReply::finished, reply, &QNetworkReply::deleteLater);
|
||||||
connect(reply, &QNetworkReply::finished, this, [reply, homeId, zoneId, this] {
|
connect(reply, &QNetworkReply::finished, this, [reply, homeId, zoneId, this] {
|
||||||
|
|
||||||
|
|
@ -399,7 +399,7 @@ void Tado::getZoneState(const QString &homeId, const QString &zoneId)
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
qCDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
qCDebug(dcTado()) << "Zone status received:" << qUtf8Printable(data.toJson(QJsonDocument::Indented));
|
qCDebug(dcTado()) << "Zone status received:" << qUtf8Printable(data.toJson(QJsonDocument::Indented));
|
||||||
|
|
@ -439,12 +439,12 @@ QUuid Tado::setOverlay(const QString &homeId, const QString &zoneId, bool power,
|
||||||
{
|
{
|
||||||
if (!m_apiAvailable) {
|
if (!m_apiAvailable) {
|
||||||
qCWarning(dcTado()) << "Not sending request, get API credentials first";
|
qCWarning(dcTado()) << "Not sending request, get API credentials first";
|
||||||
return "";
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_accessToken.isEmpty()) {
|
if(m_accessToken.isEmpty()) {
|
||||||
qCWarning(dcTado()) << "Not sending request, get the access token first";
|
qCWarning(dcTado()) << "Not sending request, get the access token first";
|
||||||
return "";
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid requestId = QUuid::createUuid();
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
|
@ -493,7 +493,7 @@ QUuid Tado::setOverlay(const QString &homeId, const QString &zoneId, bool power,
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
qCDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QVariantMap map = data.toVariant().toMap();
|
QVariantMap map = data.toVariant().toMap();
|
||||||
|
|
@ -516,12 +516,12 @@ QUuid Tado::deleteOverlay(const QString &homeId, const QString &zoneId)
|
||||||
{
|
{
|
||||||
if (!m_apiAvailable) {
|
if (!m_apiAvailable) {
|
||||||
qCWarning(dcTado()) << "Not sending request, get API credentials first";
|
qCWarning(dcTado()) << "Not sending request, get API credentials first";
|
||||||
return "";
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_accessToken.isEmpty()) {
|
if(m_accessToken.isEmpty()) {
|
||||||
qCWarning(dcTado()) << "Not sending request, get the access token first";
|
qCWarning(dcTado()) << "Not sending request, get the access token first";
|
||||||
return "";
|
return QUuid();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUuid requestId = QUuid::createUuid();
|
QUuid requestId = QUuid::createUuid();
|
||||||
|
|
@ -560,7 +560,7 @@ QUuid Tado::deleteOverlay(const QString &homeId, const QString &zoneId)
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
QJsonDocument data = QJsonDocument::fromJson(reply->readAll(), &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
qCDebug(dcTado()) << "Get Token: Recieved invalid JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -618,7 +618,7 @@ void Tado::requestAuthenticationToken()
|
||||||
QJsonParseError error;
|
QJsonParseError error;
|
||||||
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
QJsonDocument responseJsonDoc = QJsonDocument::fromJson(data, &error);
|
||||||
if (error.error != QJsonParseError::NoError) {
|
if (error.error != QJsonParseError::NoError) {
|
||||||
qDebug(dcTado()) << "Authentication received invalid JSON object:" << data;
|
qCDebug(dcTado()) << "Authentication received invalid JSON object:" << data;
|
||||||
emit startAuthenticationFinished(false);
|
emit startAuthenticationFinished(false);
|
||||||
setAuthenticationStatus(false);
|
setAuthenticationStatus(false);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
include(../plugins.pri)
|
include(../plugins.pri)
|
||||||
|
|
||||||
QT += network
|
QT *= network
|
||||||
|
|
||||||
TARGET = $$qtLibraryTarget(nymea_integrationplugintado)
|
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
integrationplugintado.cpp \
|
integrationplugintado.cpp \
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue