LEDDevices - WLED enhancements and minor fixes (#1204)

* Yeelight minor updates

* Add Timeout to REST API

* LEDDevice - Correct storeState

* Add WaitTime function

* Always show HW-LEDCount for configuration

* WLED - New features ("live" support, storing state and identification)

* Yeelight - Refactoring

* Cololight - Refactoring

* Karate - getProperties Support

* Atmo - getProperties Support

* AtmoOrb - refactoring

* Nanoleaf - Refactoring, New "Shapes" considerations

* PhilipHue - Minor corrections

* Update Changelog
This commit is contained in:
LordGrey
2021-03-19 22:52:04 +01:00
committed by GitHub
parent 956edf9e78
commit 41af5c1b9e
20 changed files with 609 additions and 257 deletions

View File

@@ -10,6 +10,48 @@
#include <QUrlQuery>
#include <QJsonDocument>
#include <QBasicTimer>
#include <QTimerEvent>
//Set QNetworkReply timeout without external timer
//https://stackoverflow.com/questions/37444539/how-to-set-qnetworkreply-timeout-without-external-timer
class ReplyTimeout : public QObject {
Q_OBJECT
public:
enum HandleMethod { Abort, Close };
ReplyTimeout(QNetworkReply* reply, const int timeout, HandleMethod method = Abort) :
QObject(reply), m_method(method)
{
Q_ASSERT(reply);
if (reply && reply->isRunning()) {
m_timer.start(timeout, this);
connect(reply, &QNetworkReply::finished, this, &QObject::deleteLater);
}
}
static void set(QNetworkReply* reply, const int timeout, HandleMethod method = Abort)
{
new ReplyTimeout(reply, timeout, method);
}
protected:
QBasicTimer m_timer;
HandleMethod m_method;
void timerEvent(QTimerEvent * ev) override {
if (!m_timer.isActive() || ev->timerId() != m_timer.timerId())
return;
auto reply = static_cast<QNetworkReply*>(parent());
if (reply->isRunning())
{
if (m_method == Close)
reply->close();
else if (m_method == Abort)
reply->abort();
m_timer.stop();
}
}
};
///
/// Response object for REST-API calls and JSON-responses
///
@@ -191,7 +233,7 @@ private:
/// @param[in/out] path to be updated
/// @param[in] path, element to be appended
///
void appendPath (QString &path, const QString &appendPath) const;
static void appendPath (QString &path, const QString &appendPath) ;
Logger* _log;