fixed color temperature, reduced fade time

master
bernhard.trinnes 2020-07-24 18:27:04 +02:00
parent 1d4563c6af
commit 83c22c0cfc
4 changed files with 24 additions and 79 deletions

View File

@ -334,7 +334,7 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);}); connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info); m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId) { } else if (action.actionTypeId() == colorBulbColorTemperatureActionTypeId) {
int colorTemperature = 6500 - (action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toUInt() * -11.12); int colorTemperature = 6500 - (action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toUInt() * 8); //range 2500 to 6500 kelvin
if (!thing->stateValue(colorBulbPowerStateTypeId).toBool()){ if (!thing->stateValue(colorBulbPowerStateTypeId).toBool()){
if (cloudDevice) { if (cloudDevice) {
lifxCloud->setPower(lightId, true); lifxCloud->setPower(lightId, true);
@ -358,25 +358,19 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
lifx->setPower(true); lifx->setPower(true);
} }
} }
QString effectString = action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toString(); QString effectString = action.param(colorBulbEffectActionEffectParamTypeId).value().toString();
int requestId; int requestId;
LifxCloud::Effect effect; LifxCloud::Effect effect;
if (effectString == "None") { if (effectString == "None") {
effect = LifxCloud::EffectNone; effect = LifxCloud::EffectNone;
} else if (effectString == "Breathe") { } else if (effectString == "Breathe") {
effect = LifxCloud::EffectBreathe; effect = LifxCloud::EffectBreathe;
} else if (effectString == "Move") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Morph") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Flame") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Pulse") { } else if (effectString == "Pulse") {
effect = LifxCloud::EffectMove; effect = LifxCloud::EffectPulse;
} }
if (cloudDevice) { if (cloudDevice) {
QColor color = QColor(thing->stateValue(colorBulbColorStateTypeId).toString()); //QColor color = QColor(thing->stateValue(colorBulbColorStateTypeId).toString());
requestId = lifxCloud->setEffect(lightId, effect, color); requestId = lifxCloud->setEffect(lightId, effect, "#FFFFFF");
} else { } else {
qCWarning(dcLifx()) << "LAN devices are not yet supported"; qCWarning(dcLifx()) << "LAN devices are not yet supported";
info->finish(Thing::ThingErrorHardwareNotAvailable); info->finish(Thing::ThingErrorHardwareNotAvailable);
@ -415,39 +409,6 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
} }
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);}); connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info); m_asyncActions.insert(requestId, info);
} else if (action.actionTypeId() == dimmableBulbEffectStateTypeId) {
if (!thing->stateValue(colorBulbPowerStateTypeId).toBool()){
if (cloudDevice) {
lifxCloud->setPower(lightId, true);
} else {
lifx->setPower(true);
}
}
QString effectString = action.param(dimmableBulbColorTemperatureActionColorTemperatureParamTypeId).value().toString();
int requestId;
LifxCloud::Effect effect;
if (effectString == "None") {
effect = LifxCloud::EffectNone;
} else if (effectString == "Breathe") {
effect = LifxCloud::EffectBreathe;
} else if (effectString == "Move") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Morph") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Flame") {
effect = LifxCloud::EffectMove;
} else if (effectString == "Pulse") {
effect = LifxCloud::EffectMove;
}
if (cloudDevice) {
requestId = lifxCloud->setEffect(lightId, effect, QColor("0xffffff"));
} else {
qCWarning(dcLifx()) << "LAN devices are not yet supported";
info->finish(Thing::ThingErrorHardwareNotAvailable);
return;
}
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
m_asyncActions.insert(requestId, info);
} else { } else {
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8()); Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
} }

View File

@ -129,9 +129,6 @@
"possibleValues": [ "possibleValues": [
"None", "None",
"Breathe", "Breathe",
"Move",
"Morph",
"Flame",
"Pulse" "Pulse"
], ],
"writable": true "writable": true
@ -197,24 +194,6 @@
"minValue": 153, "minValue": 153,
"maxValue": 500, "maxValue": 500,
"writable": true "writable": true
},
{
"id": "be47c474-eca1-479e-9393-68281a43d72a",
"name": "effect",
"displayName": "Effect",
"displayNameEvent": "Effect changed",
"displayNameAction": "Set effect",
"type": "QString",
"defaultValue": "None",
"possibleValues": [
"None",
"Breathe",
"Move",
"Morph",
"Flame",
"Pulse"
],
"writable": true
} }
] ]
} }

View File

@ -34,6 +34,7 @@
#include <QNetworkReply> #include <QNetworkReply>
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QUrl> #include <QUrl>
#include <QUrlQuery>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
@ -236,14 +237,16 @@ int LifxCloud::setEffect(const QString &lightId, LifxCloud::Effect effect, QColo
} }
int requestId = qrand(); int requestId = qrand();
QNetworkRequest request; QNetworkRequest request;
QJsonObject payload; QUrlQuery params;
switch (effect) { switch (effect) {
case LifxCloud::EffectNone: case LifxCloud::EffectNone:
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/off").arg(lightId))); request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/off").arg(lightId)));
break; break;
case LifxCloud::EffectBreathe: case LifxCloud::EffectBreathe:
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/breathe").arg(lightId))); request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/breathe").arg(lightId)));
payload["color"] = color.name(); params.addQueryItem("color", color.name().trimmed());
params.addQueryItem("period", "2");
params.addQueryItem("cycles", "3");
break; break;
case LifxCloud::EffectMove: case LifxCloud::EffectMove:
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/move").arg(lightId))); request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/move").arg(lightId)));
@ -256,19 +259,21 @@ int LifxCloud::setEffect(const QString &lightId, LifxCloud::Effect effect, QColo
break; break;
case LifxCloud::EffectPulse: case LifxCloud::EffectPulse:
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/pulse").arg(lightId))); request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/pulse").arg(lightId)));
payload["color"] = color.name(); params.addQueryItem("color", color.name().trimmed());
params.addQueryItem("period", "2");
params.addQueryItem("cycles", "3");
break; break;
} }
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded.");
request.setRawHeader("Authorization","Bearer "+m_authorizationToken); request.setRawHeader("Authorization","Bearer "+m_authorizationToken);
QJsonDocument doc; qCDebug(dcLifx()) << "Set effect request" << request.url() << params.toString().toUtf8();
doc.setObject(payload);
QNetworkReply *reply = m_networkManager->put(request, doc.toJson()); QNetworkReply *reply = m_networkManager->post(request, params.toString().toUtf8());
connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater); connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater);
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
QByteArray rawData = reply->readAll(); QByteArray rawData = reply->readAll();
qCDebug(dcLifx()) << "Got set state reply" << rawData; qCDebug(dcLifx()) << "Got set effect reply" << rawData;
emit requestExecuted(requestId, checkHttpStatusCode(reply)); emit requestExecuted(requestId, checkHttpStatusCode(reply));
}); });
return requestId; return requestId;

View File

@ -111,15 +111,15 @@ public:
void listLights(); void listLights();
void listScenes(); void listScenes();
int setPower(const QString &lightId, bool power, int duration = 5); int setPower(const QString &lightId, bool power, int duration = 0);
int setBrightnesss(const QString &lightId, int brightness, int duration = 5); int setBrightnesss(const QString &lightId, int brightness, int duration = 0);
int setColor(const QString &lightId, QColor color, int duration = 5); int setColor(const QString &lightId, QColor color, int duration = 0);
int setColorTemperature(const QString &lightId, int kelvin, int duration = 5); int setColorTemperature(const QString &lightId, int kelvin, int duration = 0);
int setInfrared(const QString &lightId, int infrared, int duration = 5); int setInfrared(const QString &lightId, int infrared, int duration = 0);
int activateScene(const QString &sceneId); int activateScene(const QString &sceneId);
int setEffect(const QString &lightId, Effect effect, QColor color); int setEffect(const QString &lightId, Effect effect, QColor color = "#FFFFFF");
private: private:
NetworkAccessManager *m_networkManager = nullptr; NetworkAccessManager *m_networkManager = nullptr;