fixed color temperature, reduced fade time
parent
1d4563c6af
commit
83c22c0cfc
|
|
@ -334,7 +334,7 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
|
|||
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
|
||||
m_asyncActions.insert(requestId, info);
|
||||
} 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 (cloudDevice) {
|
||||
lifxCloud->setPower(lightId, true);
|
||||
|
|
@ -358,25 +358,19 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
|
|||
lifx->setPower(true);
|
||||
}
|
||||
}
|
||||
QString effectString = action.param(colorBulbColorTemperatureActionColorTemperatureParamTypeId).value().toString();
|
||||
QString effectString = action.param(colorBulbEffectActionEffectParamTypeId).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;
|
||||
effect = LifxCloud::EffectPulse;
|
||||
}
|
||||
if (cloudDevice) {
|
||||
QColor color = QColor(thing->stateValue(colorBulbColorStateTypeId).toString());
|
||||
requestId = lifxCloud->setEffect(lightId, effect, color);
|
||||
//QColor color = QColor(thing->stateValue(colorBulbColorStateTypeId).toString());
|
||||
requestId = lifxCloud->setEffect(lightId, effect, "#FFFFFF");
|
||||
} else {
|
||||
qCWarning(dcLifx()) << "LAN devices are not yet supported";
|
||||
info->finish(Thing::ThingErrorHardwareNotAvailable);
|
||||
|
|
@ -415,39 +409,6 @@ void IntegrationPluginLifx::executeAction(ThingActionInfo *info)
|
|||
}
|
||||
connect(info, &ThingActionInfo::aborted, this, [requestId, this] {m_asyncActions.remove(requestId);});
|
||||
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 {
|
||||
Q_ASSERT_X(false, "executeAction", QString("Unhandled actionTypeId: %1").arg(action.actionTypeId().toString()).toUtf8());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,9 +129,6 @@
|
|||
"possibleValues": [
|
||||
"None",
|
||||
"Breathe",
|
||||
"Move",
|
||||
"Morph",
|
||||
"Flame",
|
||||
"Pulse"
|
||||
],
|
||||
"writable": true
|
||||
|
|
@ -197,24 +194,6 @@
|
|||
"minValue": 153,
|
||||
"maxValue": 500,
|
||||
"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
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@
|
|||
#include <QNetworkReply>
|
||||
#include <QNetworkRequest>
|
||||
#include <QUrl>
|
||||
#include <QUrlQuery>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
|
@ -236,14 +237,16 @@ int LifxCloud::setEffect(const QString &lightId, LifxCloud::Effect effect, QColo
|
|||
}
|
||||
int requestId = qrand();
|
||||
QNetworkRequest request;
|
||||
QJsonObject payload;
|
||||
QUrlQuery params;
|
||||
switch (effect) {
|
||||
case LifxCloud::EffectNone:
|
||||
request.setUrl(QUrl(QString("https://api.lifx.com/v1/lights/id:%1/effects/off").arg(lightId)));
|
||||
break;
|
||||
case LifxCloud::EffectBreathe:
|
||||
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;
|
||||
case LifxCloud::EffectMove:
|
||||
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;
|
||||
case LifxCloud::EffectPulse:
|
||||
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;
|
||||
}
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/x-www-form-urlencoded.");
|
||||
request.setRawHeader("Authorization","Bearer "+m_authorizationToken);
|
||||
QJsonDocument doc;
|
||||
doc.setObject(payload);
|
||||
QNetworkReply *reply = m_networkManager->put(request, doc.toJson());
|
||||
qCDebug(dcLifx()) << "Set effect request" << request.url() << params.toString().toUtf8();
|
||||
|
||||
QNetworkReply *reply = m_networkManager->post(request, params.toString().toUtf8());
|
||||
connect(reply, &QNetworkReply::finished, &QNetworkReply::deleteLater);
|
||||
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
|
||||
|
||||
QByteArray rawData = reply->readAll();
|
||||
qCDebug(dcLifx()) << "Got set state reply" << rawData;
|
||||
qCDebug(dcLifx()) << "Got set effect reply" << rawData;
|
||||
emit requestExecuted(requestId, checkHttpStatusCode(reply));
|
||||
});
|
||||
return requestId;
|
||||
|
|
|
|||
|
|
@ -111,15 +111,15 @@ public:
|
|||
|
||||
void listLights();
|
||||
void listScenes();
|
||||
int setPower(const QString &lightId, bool power, int duration = 5);
|
||||
int setBrightnesss(const QString &lightId, int brightness, int duration = 5);
|
||||
int setColor(const QString &lightId, QColor color, int duration = 5);
|
||||
int setColorTemperature(const QString &lightId, int kelvin, int duration = 5);
|
||||
int setInfrared(const QString &lightId, int infrared, int duration = 5);
|
||||
int setPower(const QString &lightId, bool power, int duration = 0);
|
||||
int setBrightnesss(const QString &lightId, int brightness, int duration = 0);
|
||||
int setColor(const QString &lightId, QColor color, int duration = 0);
|
||||
int setColorTemperature(const QString &lightId, int kelvin, int duration = 0);
|
||||
int setInfrared(const QString &lightId, int infrared, int duration = 0);
|
||||
|
||||
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:
|
||||
NetworkAccessManager *m_networkManager = nullptr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue