Nanoleaf Updates (#1299)

* Discover additional Nanoleaf devices

* Fix Nanoleaf not turning on

* Added LGTM configuration file

* Allow to pass QJsonObject as payload for put

* Nanoleaf - Support Restore State & Overwrite Brightness

* Removed because this is already included

Co-authored-by: Markus <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
LordGrey
2021-08-31 10:55:49 +02:00
committed by GitHub
parent 12cdd1d58a
commit f0bd38d473
5 changed files with 301 additions and 50 deletions

View File

@@ -5,6 +5,7 @@
#include <QEventLoop>
#include <QNetworkReply>
#include <QByteArray>
#include <QJsonObject>
//std includes
#include <iostream>
@@ -154,16 +155,21 @@ httpResponse ProviderRestApi::get(const QUrl &url)
return response;
}
httpResponse ProviderRestApi::put(const QString &body)
httpResponse ProviderRestApi::put(const QJsonObject &body)
{
return put( getUrl(), body );
return put( getUrl(), QJsonDocument(body).toJson(QJsonDocument::Compact));
}
httpResponse ProviderRestApi::put(const QUrl &url, const QString &body)
httpResponse ProviderRestApi::put(const QString &body)
{
return put( getUrl(), body.toUtf8() );
}
httpResponse ProviderRestApi::put(const QUrl &url, const QByteArray &body)
{
// Perform request
QNetworkRequest request(url);
QNetworkReply* reply = _networkManager->put(request, body.toUtf8());
QNetworkReply* reply = _networkManager->put(request, body);
// Connect requestFinished signal to quit slot of the loop.
QEventLoop loop;
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
@@ -178,7 +184,7 @@ httpResponse ProviderRestApi::put(const QUrl &url, const QString &body)
{
if(reply->error() != QNetworkReply::NoError)
{
Debug(_log, "PUT: [%s] [%s]", QSTRING_CSTR( url.toString() ), QSTRING_CSTR( body ) );
Debug(_log, "PUT: [%s] [%s]", QSTRING_CSTR( url.toString() ),body.constData() );
}
response = getResponse(reply);
}