From a642f25988a5d7663d7be6f0f85e9dbb58a7de44 Mon Sep 17 00:00:00 2001 From: Boernsman Date: Fri, 3 Jan 2020 15:26:34 +0100 Subject: [PATCH] fixed QColor to saturation conversion --- nanoleaf/devicepluginnanoleaf.cpp | 55 +++++---- nanoleaf/devicepluginnanoleaf.h | 4 +- nanoleaf/nanoleaf.cpp | 183 +++++++++++++++--------------- nanoleaf/nanoleaf.h | 9 +- 4 files changed, 136 insertions(+), 115 deletions(-) diff --git a/nanoleaf/devicepluginnanoleaf.cpp b/nanoleaf/devicepluginnanoleaf.cpp index 4882aa1c..bd68ef87 100644 --- a/nanoleaf/devicepluginnanoleaf.cpp +++ b/nanoleaf/devicepluginnanoleaf.cpp @@ -230,11 +230,6 @@ void DevicePluginNanoleaf::browserItem(BrowserItemResult *result) { Q_UNUSED(result) qCDebug(dcNanoleaf()) << "BrowserItem called"; - //Device *device = result->device(); - //Nanoleaf *nanoleaf = m_nanoleafConnections.value(device->id()); - //nanoleaf->setEffect(info.); - //result-> - //m_asyncBrowseItems.insert(nanoleaf, result);*/ } void DevicePluginNanoleaf::executeBrowserItem(BrowserActionInfo *info) @@ -327,7 +322,7 @@ void DevicePluginNanoleaf::onControllerInfoReceived(const Nanoleaf::ControllerIn Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Controller Info received" << controllerInfo.name << controllerInfo.firmwareVersion; + //qCDebug(dcNanoleaf()) << "Controller Info received" << controllerInfo.name << controllerInfo.firmwareVersion; device->setParamValue(lightPanelsDeviceFirmwareVersionParamTypeId, controllerInfo.firmwareVersion); } @@ -337,7 +332,7 @@ void DevicePluginNanoleaf::onPowerReceived(bool power) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Power received" << power; + //qCDebug(dcNanoleaf()) << "Power received" << power; device->setStateValue(lightPanelsPowerStateTypeId, power); } @@ -347,18 +342,37 @@ void DevicePluginNanoleaf::onBrightnessReceived(int percentage) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Brightness received" << percentage; + //qCDebug(dcNanoleaf()) << "Brightness received" << percentage; device->setStateValue(lightPanelsBrightnessStateTypeId, percentage); } -void DevicePluginNanoleaf::onColorModeReceived(const QString &colorMode) +void DevicePluginNanoleaf::onColorReceived(QColor color) { Nanoleaf *nanoleaf = static_cast(sender()); Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Color mode received" << colorMode; - device->setStateValue(lightPanelsColorModeStateTypeId, colorMode); + //qCDebug(dcNanoleaf()) << "Color received" << color.toRgb(); + device->setStateValue(lightPanelsColorStateTypeId, color); +} + +void DevicePluginNanoleaf::onColorModeReceived(Nanoleaf::ColorMode colorMode) +{ + Nanoleaf *nanoleaf = static_cast(sender()); + Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); + if (!device) + return; + switch (colorMode) { + case Nanoleaf::ColorMode::ColorTemperatureMode: + device->setStateValue(lightPanelsColorModeStateTypeId, tr("Color temperature")); + break; + case Nanoleaf::ColorMode::HueSaturationMode: + device->setStateValue(lightPanelsColorModeStateTypeId, tr("Hue/Saturation")); + break; + case Nanoleaf::ColorMode::EffectMode: + device->setStateValue(lightPanelsColorModeStateTypeId, tr("Effect")); + break; + } } void DevicePluginNanoleaf::onHueReceived(int hue) @@ -367,9 +381,10 @@ void DevicePluginNanoleaf::onHueReceived(int hue) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Hue received" << hue; - m_hues.insert(device->id(), hue); - nanoleaf->getSaturation(); + //qCDebug(dcNanoleaf()) << "Hue received" << hue; + QColor color = QColor(device->stateValue(lightPanelsColorStateTypeId).toString()); + color.setHsv(hue, color.saturation(), color.value()); + device->setStateValue(lightPanelsColorStateTypeId, color); } void DevicePluginNanoleaf::onSaturationReceived(int saturation) @@ -378,9 +393,9 @@ void DevicePluginNanoleaf::onSaturationReceived(int saturation) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Saturation received" << saturation; - QColor color; - color.setHsv(m_hues.value(device->id()), saturation, 100); + //qCDebug(dcNanoleaf()) << "Saturation received" << saturation; + QColor color = QColor(device->stateValue(lightPanelsColorStateTypeId).toString()); + color.setHsv(color.hue(), saturation, color.value()); device->setStateValue(lightPanelsColorStateTypeId, color); } @@ -390,7 +405,7 @@ void DevicePluginNanoleaf::onEffectListReceived(const QStringList &effects) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Effect list received" << effects; + //qCDebug(dcNanoleaf()) << "Effect list received" << effects; if (m_asyncBrowseResults.contains(nanoleaf)) { BrowseResult *result = m_asyncBrowseResults.take(nanoleaf); @@ -413,7 +428,7 @@ void DevicePluginNanoleaf::onColorTemperatureReceived(int kelvin) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Color temperature received" << kelvin; + //qCDebug(dcNanoleaf()) << "Color temperature received" << kelvin; //NOTE: this is just a rough estimation of the mired value int mired = static_cast(kelvin/11.12); //FIXME device->setStateValue(lightPanelsColorTemperatureStateTypeId, mired); @@ -425,7 +440,7 @@ void DevicePluginNanoleaf::onSelectedEffectReceived(const QString &effect) Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf)); if (!device) return; - qCDebug(dcNanoleaf()) << "Selected effect received" << effect; + //qCDebug(dcNanoleaf()) << "Selected effect received" << effect; device->setStateValue(lightPanelsEffectNameStateTypeId, QString(effect).remove('"').remove('*')); } diff --git a/nanoleaf/devicepluginnanoleaf.h b/nanoleaf/devicepluginnanoleaf.h index 677e6d04..9f464119 100644 --- a/nanoleaf/devicepluginnanoleaf.h +++ b/nanoleaf/devicepluginnanoleaf.h @@ -72,7 +72,6 @@ private: QHash m_asyncBrowseResults; QHash m_asyncBrowserItem; - QHash m_hues; Nanoleaf *createNanoleafConnection(const QHostAddress &address, int port); @@ -85,7 +84,8 @@ public slots: void onControllerInfoReceived(const Nanoleaf::ControllerInfo &controllerInfo); void onPowerReceived(bool power); void onBrightnessReceived(int percentage); - void onColorModeReceived(const QString &colorMode); + void onColorReceived(QColor color); + void onColorModeReceived(Nanoleaf::ColorMode colorMode); void onHueReceived(int hue); void onSaturationReceived(int percentage); void onEffectListReceived(const QStringList &effects); diff --git a/nanoleaf/nanoleaf.cpp b/nanoleaf/nanoleaf.cpp index f6f9dc54..3cc4648e 100644 --- a/nanoleaf/nanoleaf.cpp +++ b/nanoleaf/nanoleaf.cpp @@ -85,13 +85,13 @@ void Nanoleaf::addUser() request.setUrl(url); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); QNetworkReply *reply = m_networkManager->post(request, ""); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); // Check HTTP status code - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { if (reply->error() == QNetworkReply::HostNotFoundError) { emit connectionChanged(false); } @@ -127,12 +127,12 @@ void Nanoleaf::deleteUser() QNetworkRequest request; request.setUrl(url); QNetworkReply *reply = m_networkManager->deleteResource(request); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; } @@ -151,7 +151,7 @@ void Nanoleaf::getControllerInfo() QNetworkRequest request; request.setUrl(url); QNetworkReply *reply = m_networkManager->get(request); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); @@ -184,20 +184,31 @@ void Nanoleaf::getControllerInfo() if (state.contains("on")) { emit powerReceived(state["on"].toMap().value("value").toBool()); } - if (state.contains("brightness")) { - emit brightnessReceived(state["brightness"].toMap().value("value").toInt()); - } - if (state.contains("hue")) { - emit hueReceived(state["hue"].toMap().value("value").toInt()); - } - if (state.contains("sat")) { - emit saturationReceived(state["sat"].toMap().value("value").toInt()); + if (state.contains("hue") && state.contains("sat") && state.contains("brightness")) { + int brightness = state["brightness"].toMap().value("value").toInt(); + emit brightnessReceived(brightness); + int hue = state["hue"].toMap().value("value").toInt(); + emit hueReceived(hue); + int sat = state["sat"].toMap().value("value").toInt(); + emit saturationReceived(sat); + QColor color; + color.setHsv(hue, sat, brightness); + emit colorReceived(color); } if (state.contains("ct")) { emit colorTemperatureReceived(state["ct"].toMap().value("value").toInt()); } if (state.contains("colorMode")) { - emit colorModeReceived(state["colorMode"].toString()); + QString colorModeString = state["colorMode"].toString(); + if (colorModeString == "effect") { + emit colorModeReceived(ColorMode::EffectMode); + } else if (colorModeString == "hs") { + emit colorModeReceived(ColorMode::HueSaturationMode); + } else if (colorModeString == "ct") { + emit colorModeReceived(ColorMode::ColorTemperatureMode); + } else { + qCWarning(dcNanoleaf()) << "Unrecognized color mode"; + } } } if (map.contains("effects")) { @@ -228,12 +239,12 @@ void Nanoleaf::getPower() QNetworkRequest request; request.setUrl(url); QNetworkReply *reply = m_networkManager->get(request); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -261,12 +272,12 @@ void Nanoleaf::getHue() QNetworkRequest request; request.setUrl(url); QNetworkReply *reply = m_networkManager->get(request); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; } @@ -297,7 +308,7 @@ void Nanoleaf::getBrightness() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; } @@ -328,7 +339,7 @@ void Nanoleaf::getSaturation() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; } @@ -359,7 +370,7 @@ void Nanoleaf::getColorTemperature() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -391,7 +402,7 @@ void Nanoleaf::getColorMode() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -402,9 +413,17 @@ void Nanoleaf::getColorMode() qDebug(dcNanoleaf()) << "Recieved invalide JSON object"; return; } - QString colorMode = data.toVariant().toMap().value("value").toString(); emit connectionChanged(true); - emit colorModeReceived(colorMode); + QString colorModeString = data.toVariant().toMap().value("value").toString(); + if (colorModeString == "effect") { + emit colorModeReceived(ColorMode::EffectMode); + } else if (colorModeString == "hs") { + emit colorModeReceived(ColorMode::HueSaturationMode); + } else if (colorModeString == "ct") { + emit colorModeReceived(ColorMode::ColorTemperatureMode); + } else { + qCWarning(dcNanoleaf()) << "Unrecognized color mode"; + } }); } @@ -435,7 +454,7 @@ void Nanoleaf::registerForEvents() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -450,29 +469,39 @@ void Nanoleaf::registerForEvents() QVariantList events = data.toVariant().toList(); foreach (QVariant variant, events) { - QVariantMap event = variant.toMap(); - switch (event["attr"].toInt()) { - case 1: //ON - emit powerReceived(event["value"].toBool()); - break; - case 2: //Brightness - emit brightnessReceived(event["value"].toInt()); - break; - case 3: //Hue - emit hueReceived(event["value"].toInt()); - break; - case 4: //Saturation - emit saturationReceived(event["value"].toInt()); - break; - case 5: //Color Temperature - emit colorTemperatureReceived(event["value"].toInt()); - break; - case 6: //colorMode - emit colorModeReceived(event["value"].toString()); - break; - default: - qCWarning(dcNanoleaf()) << "Unrecognised Event received"; - } + QVariantMap event = variant.toMap(); + switch (event["attr"].toInt()) { + case 1: //ON + emit powerReceived(event["value"].toBool()); + break; + case 2: //Brightness + emit brightnessReceived(event["value"].toInt()); + break; + case 3: //Hue + emit hueReceived(event["value"].toInt()); + break; + case 4: //Saturation + emit saturationReceived(event["value"].toInt()); + break; + case 5: //Color Temperature + emit colorTemperatureReceived(event["value"].toInt()); + break; + case 6: { //colorMode + QString colorModeString = event["value"].toString(); + if (colorModeString == "effect") { + emit colorModeReceived(ColorMode::EffectMode); + } else if (colorModeString == "hs") { + emit colorModeReceived(ColorMode::HueSaturationMode); + } else if (colorModeString == "ct") { + emit colorModeReceived(ColorMode::ColorTemperatureMode); + } else { + qCWarning(dcNanoleaf()) << "Unrecognized color mode"; + } + break; + } + default: + qCWarning(dcNanoleaf()) << "Unrecognised Event received"; + } } }); @@ -497,12 +526,12 @@ QUuid Nanoleaf::setPower(bool power) request.setUrl(url); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); QNetworkReply *reply = m_networkManager->put(request, body.toJson()); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; @@ -515,38 +544,8 @@ QUuid Nanoleaf::setPower(bool power) QUuid Nanoleaf::setColor(QColor color) { - QUuid requestId = QUuid::createUuid(); - QUrl url; - url.setHost(m_address.toString()); - url.setPort(m_port); - url.setScheme("http"); - url.setPath(QString("/api/v1/%1/state").arg(m_authToken)); - - QVariantMap map; - QVariantMap hue; - hue["value"] = color.hue(); - map.insert("hue", hue); - QVariantMap sat; - sat["value"] = color.saturation(); - map.insert("sat", sat); - QJsonDocument body = QJsonDocument::fromVariant(map); - - QNetworkRequest request; - request.setUrl(url); - request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); - QNetworkReply *reply = m_networkManager->put(request, body.toJson()); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); - connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { - reply->deleteLater(); - int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - - if (status != 204 || reply->error() != QNetworkReply::NoError) { - emit requestExecuted(requestId, false); - qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); - return; - } - emit requestExecuted(requestId, true); - }); + QUuid requestId = setHue(color.hue()); + setSaturation(static_cast(color.saturation()/2.55)); //QColor saturation is 0-255 return requestId; } @@ -569,12 +568,12 @@ QUuid Nanoleaf::setHue(int hue) request.setUrl(url); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); QNetworkReply *reply = m_networkManager->put(request, body.toJson()); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; @@ -603,12 +602,12 @@ QUuid Nanoleaf::setBrightness(int percentage) request.setUrl(url); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); QNetworkReply *reply = m_networkManager->put(request, body.toJson()); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + //qDebug(dcNanoleaf()) << "Sending request" << request.url(); connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; @@ -637,12 +636,12 @@ QUuid Nanoleaf::setSaturation(int percentage) request.setUrl(url); request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json"); QNetworkReply *reply = m_networkManager->put(request, body.toJson()); - qDebug(dcNanoleaf()) << "Sending request" << request.url(); + qDebug(dcNanoleaf()) << "Sending request" << request.url() << body.toJson(); connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] { reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; @@ -684,7 +683,7 @@ QUuid Nanoleaf::setKelvin(int kelvin) reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; @@ -709,7 +708,7 @@ void Nanoleaf::getEffects() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -745,7 +744,7 @@ void Nanoleaf::getSelectedEffect() reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 200 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); emit connectionChanged(false); return; @@ -778,7 +777,7 @@ QUuid Nanoleaf::setEffect(const QString &effect) reply->deleteLater(); int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); - if (status != 204 || reply->error() != QNetworkReply::NoError) { + if (status < 200 || status > 204 || reply->error() != QNetworkReply::NoError) { emit requestExecuted(requestId, false); qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString(); return; diff --git a/nanoleaf/nanoleaf.h b/nanoleaf/nanoleaf.h index a47930fa..cb9b2289 100644 --- a/nanoleaf/nanoleaf.h +++ b/nanoleaf/nanoleaf.h @@ -50,6 +50,12 @@ public: QString model; }; + enum ColorMode { + EffectMode, + HueSaturationMode, + ColorTemperatureMode + }; + enum GestureID { SingleTap = 0, DoubleTap = 1, @@ -115,10 +121,11 @@ signals: void authTokenRecieved(const QString &token); void powerReceived(bool power); void brightnessReceived(int percentage); - void colorModeReceived(const QString &colorMode); + void colorModeReceived(ColorMode colorMode); void hueReceived(int hue); void saturationReceived(int percentage); void effectListReceived(const QStringList &effects); + void colorReceived(QColor color); void colorTemperatureReceived(int kelvin); void selectedEffectReceived(const QString &effect);