fixed QColor to saturation conversion
parent
6771504edf
commit
a642f25988
|
|
@ -230,11 +230,6 @@ void DevicePluginNanoleaf::browserItem(BrowserItemResult *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(result)
|
Q_UNUSED(result)
|
||||||
qCDebug(dcNanoleaf()) << "BrowserItem called";
|
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)
|
void DevicePluginNanoleaf::executeBrowserItem(BrowserActionInfo *info)
|
||||||
|
|
@ -327,7 +322,7 @@ void DevicePluginNanoleaf::onControllerInfoReceived(const Nanoleaf::ControllerIn
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Controller Info received" << controllerInfo.name << controllerInfo.firmwareVersion;
|
//qCDebug(dcNanoleaf()) << "Controller Info received" << controllerInfo.name << controllerInfo.firmwareVersion;
|
||||||
device->setParamValue(lightPanelsDeviceFirmwareVersionParamTypeId, controllerInfo.firmwareVersion);
|
device->setParamValue(lightPanelsDeviceFirmwareVersionParamTypeId, controllerInfo.firmwareVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -337,7 +332,7 @@ void DevicePluginNanoleaf::onPowerReceived(bool power)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Power received" << power;
|
//qCDebug(dcNanoleaf()) << "Power received" << power;
|
||||||
device->setStateValue(lightPanelsPowerStateTypeId, power);
|
device->setStateValue(lightPanelsPowerStateTypeId, power);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,18 +342,37 @@ void DevicePluginNanoleaf::onBrightnessReceived(int percentage)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Brightness received" << percentage;
|
//qCDebug(dcNanoleaf()) << "Brightness received" << percentage;
|
||||||
device->setStateValue(lightPanelsBrightnessStateTypeId, percentage);
|
device->setStateValue(lightPanelsBrightnessStateTypeId, percentage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginNanoleaf::onColorModeReceived(const QString &colorMode)
|
void DevicePluginNanoleaf::onColorReceived(QColor color)
|
||||||
{
|
{
|
||||||
Nanoleaf *nanoleaf = static_cast<Nanoleaf *>(sender());
|
Nanoleaf *nanoleaf = static_cast<Nanoleaf *>(sender());
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Color mode received" << colorMode;
|
//qCDebug(dcNanoleaf()) << "Color received" << color.toRgb();
|
||||||
device->setStateValue(lightPanelsColorModeStateTypeId, colorMode);
|
device->setStateValue(lightPanelsColorStateTypeId, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DevicePluginNanoleaf::onColorModeReceived(Nanoleaf::ColorMode colorMode)
|
||||||
|
{
|
||||||
|
Nanoleaf *nanoleaf = static_cast<Nanoleaf *>(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)
|
void DevicePluginNanoleaf::onHueReceived(int hue)
|
||||||
|
|
@ -367,9 +381,10 @@ void DevicePluginNanoleaf::onHueReceived(int hue)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Hue received" << hue;
|
//qCDebug(dcNanoleaf()) << "Hue received" << hue;
|
||||||
m_hues.insert(device->id(), hue);
|
QColor color = QColor(device->stateValue(lightPanelsColorStateTypeId).toString());
|
||||||
nanoleaf->getSaturation();
|
color.setHsv(hue, color.saturation(), color.value());
|
||||||
|
device->setStateValue(lightPanelsColorStateTypeId, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DevicePluginNanoleaf::onSaturationReceived(int saturation)
|
void DevicePluginNanoleaf::onSaturationReceived(int saturation)
|
||||||
|
|
@ -378,9 +393,9 @@ void DevicePluginNanoleaf::onSaturationReceived(int saturation)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Saturation received" << saturation;
|
//qCDebug(dcNanoleaf()) << "Saturation received" << saturation;
|
||||||
QColor color;
|
QColor color = QColor(device->stateValue(lightPanelsColorStateTypeId).toString());
|
||||||
color.setHsv(m_hues.value(device->id()), saturation, 100);
|
color.setHsv(color.hue(), saturation, color.value());
|
||||||
device->setStateValue(lightPanelsColorStateTypeId, color);
|
device->setStateValue(lightPanelsColorStateTypeId, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -390,7 +405,7 @@ void DevicePluginNanoleaf::onEffectListReceived(const QStringList &effects)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Effect list received" << effects;
|
//qCDebug(dcNanoleaf()) << "Effect list received" << effects;
|
||||||
|
|
||||||
if (m_asyncBrowseResults.contains(nanoleaf)) {
|
if (m_asyncBrowseResults.contains(nanoleaf)) {
|
||||||
BrowseResult *result = m_asyncBrowseResults.take(nanoleaf);
|
BrowseResult *result = m_asyncBrowseResults.take(nanoleaf);
|
||||||
|
|
@ -413,7 +428,7 @@ void DevicePluginNanoleaf::onColorTemperatureReceived(int kelvin)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Color temperature received" << kelvin;
|
//qCDebug(dcNanoleaf()) << "Color temperature received" << kelvin;
|
||||||
//NOTE: this is just a rough estimation of the mired value
|
//NOTE: this is just a rough estimation of the mired value
|
||||||
int mired = static_cast<int>(kelvin/11.12); //FIXME
|
int mired = static_cast<int>(kelvin/11.12); //FIXME
|
||||||
device->setStateValue(lightPanelsColorTemperatureStateTypeId, mired);
|
device->setStateValue(lightPanelsColorTemperatureStateTypeId, mired);
|
||||||
|
|
@ -425,7 +440,7 @@ void DevicePluginNanoleaf::onSelectedEffectReceived(const QString &effect)
|
||||||
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
Device *device = myDevices().findById(m_nanoleafConnections.key(nanoleaf));
|
||||||
if (!device)
|
if (!device)
|
||||||
return;
|
return;
|
||||||
qCDebug(dcNanoleaf()) << "Selected effect received" << effect;
|
//qCDebug(dcNanoleaf()) << "Selected effect received" << effect;
|
||||||
device->setStateValue(lightPanelsEffectNameStateTypeId, QString(effect).remove('"').remove('*'));
|
device->setStateValue(lightPanelsEffectNameStateTypeId, QString(effect).remove('"').remove('*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,6 @@ private:
|
||||||
|
|
||||||
QHash<Nanoleaf *, BrowseResult *> m_asyncBrowseResults;
|
QHash<Nanoleaf *, BrowseResult *> m_asyncBrowseResults;
|
||||||
QHash<QUuid, BrowserActionInfo *> m_asyncBrowserItem;
|
QHash<QUuid, BrowserActionInfo *> m_asyncBrowserItem;
|
||||||
QHash<DeviceId, int> m_hues;
|
|
||||||
|
|
||||||
Nanoleaf *createNanoleafConnection(const QHostAddress &address, int port);
|
Nanoleaf *createNanoleafConnection(const QHostAddress &address, int port);
|
||||||
|
|
||||||
|
|
@ -85,7 +84,8 @@ public slots:
|
||||||
void onControllerInfoReceived(const Nanoleaf::ControllerInfo &controllerInfo);
|
void onControllerInfoReceived(const Nanoleaf::ControllerInfo &controllerInfo);
|
||||||
void onPowerReceived(bool power);
|
void onPowerReceived(bool power);
|
||||||
void onBrightnessReceived(int percentage);
|
void onBrightnessReceived(int percentage);
|
||||||
void onColorModeReceived(const QString &colorMode);
|
void onColorReceived(QColor color);
|
||||||
|
void onColorModeReceived(Nanoleaf::ColorMode colorMode);
|
||||||
void onHueReceived(int hue);
|
void onHueReceived(int hue);
|
||||||
void onSaturationReceived(int percentage);
|
void onSaturationReceived(int percentage);
|
||||||
void onEffectListReceived(const QStringList &effects);
|
void onEffectListReceived(const QStringList &effects);
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,13 @@ void Nanoleaf::addUser()
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *reply = m_networkManager->post(request, "");
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
||||||
// Check HTTP status code
|
// 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) {
|
if (reply->error() == QNetworkReply::HostNotFoundError) {
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
}
|
}
|
||||||
|
|
@ -127,12 +127,12 @@ void Nanoleaf::deleteUser()
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
QNetworkReply *reply = m_networkManager->deleteResource(request);
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ void Nanoleaf::getControllerInfo()
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
||||||
|
|
@ -184,20 +184,31 @@ void Nanoleaf::getControllerInfo()
|
||||||
if (state.contains("on")) {
|
if (state.contains("on")) {
|
||||||
emit powerReceived(state["on"].toMap().value("value").toBool());
|
emit powerReceived(state["on"].toMap().value("value").toBool());
|
||||||
}
|
}
|
||||||
if (state.contains("brightness")) {
|
if (state.contains("hue") && state.contains("sat") && state.contains("brightness")) {
|
||||||
emit brightnessReceived(state["brightness"].toMap().value("value").toInt());
|
int brightness = state["brightness"].toMap().value("value").toInt();
|
||||||
}
|
emit brightnessReceived(brightness);
|
||||||
if (state.contains("hue")) {
|
int hue = state["hue"].toMap().value("value").toInt();
|
||||||
emit hueReceived(state["hue"].toMap().value("value").toInt());
|
emit hueReceived(hue);
|
||||||
}
|
int sat = state["sat"].toMap().value("value").toInt();
|
||||||
if (state.contains("sat")) {
|
emit saturationReceived(sat);
|
||||||
emit saturationReceived(state["sat"].toMap().value("value").toInt());
|
QColor color;
|
||||||
|
color.setHsv(hue, sat, brightness);
|
||||||
|
emit colorReceived(color);
|
||||||
}
|
}
|
||||||
if (state.contains("ct")) {
|
if (state.contains("ct")) {
|
||||||
emit colorTemperatureReceived(state["ct"].toMap().value("value").toInt());
|
emit colorTemperatureReceived(state["ct"].toMap().value("value").toInt());
|
||||||
}
|
}
|
||||||
if (state.contains("colorMode")) {
|
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")) {
|
if (map.contains("effects")) {
|
||||||
|
|
@ -228,12 +239,12 @@ void Nanoleaf::getPower()
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -261,12 +272,12 @@ void Nanoleaf::getHue()
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
QNetworkReply *reply = m_networkManager->get(request);
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -297,7 +308,7 @@ void Nanoleaf::getBrightness()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -328,7 +339,7 @@ void Nanoleaf::getSaturation()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -359,7 +370,7 @@ void Nanoleaf::getColorTemperature()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -391,7 +402,7 @@ void Nanoleaf::getColorMode()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -402,9 +413,17 @@ void Nanoleaf::getColorMode()
|
||||||
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
|
qDebug(dcNanoleaf()) << "Recieved invalide JSON object";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString colorMode = data.toVariant().toMap().value("value").toString();
|
|
||||||
emit connectionChanged(true);
|
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();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -450,29 +469,39 @@ void Nanoleaf::registerForEvents()
|
||||||
QVariantList events = data.toVariant().toList();
|
QVariantList events = data.toVariant().toList();
|
||||||
|
|
||||||
foreach (QVariant variant, events) {
|
foreach (QVariant variant, events) {
|
||||||
QVariantMap event = variant.toMap();
|
QVariantMap event = variant.toMap();
|
||||||
switch (event["attr"].toInt()) {
|
switch (event["attr"].toInt()) {
|
||||||
case 1: //ON
|
case 1: //ON
|
||||||
emit powerReceived(event["value"].toBool());
|
emit powerReceived(event["value"].toBool());
|
||||||
break;
|
break;
|
||||||
case 2: //Brightness
|
case 2: //Brightness
|
||||||
emit brightnessReceived(event["value"].toInt());
|
emit brightnessReceived(event["value"].toInt());
|
||||||
break;
|
break;
|
||||||
case 3: //Hue
|
case 3: //Hue
|
||||||
emit hueReceived(event["value"].toInt());
|
emit hueReceived(event["value"].toInt());
|
||||||
break;
|
break;
|
||||||
case 4: //Saturation
|
case 4: //Saturation
|
||||||
emit saturationReceived(event["value"].toInt());
|
emit saturationReceived(event["value"].toInt());
|
||||||
break;
|
break;
|
||||||
case 5: //Color Temperature
|
case 5: //Color Temperature
|
||||||
emit colorTemperatureReceived(event["value"].toInt());
|
emit colorTemperatureReceived(event["value"].toInt());
|
||||||
break;
|
break;
|
||||||
case 6: //colorMode
|
case 6: { //colorMode
|
||||||
emit colorModeReceived(event["value"].toString());
|
QString colorModeString = event["value"].toString();
|
||||||
break;
|
if (colorModeString == "effect") {
|
||||||
default:
|
emit colorModeReceived(ColorMode::EffectMode);
|
||||||
qCWarning(dcNanoleaf()) << "Unrecognised Event received";
|
} 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.setUrl(url);
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
@ -515,38 +544,8 @@ QUuid Nanoleaf::setPower(bool power)
|
||||||
|
|
||||||
QUuid Nanoleaf::setColor(QColor color)
|
QUuid Nanoleaf::setColor(QColor color)
|
||||||
{
|
{
|
||||||
QUuid requestId = QUuid::createUuid();
|
QUuid requestId = setHue(color.hue());
|
||||||
QUrl url;
|
setSaturation(static_cast<int>(color.saturation()/2.55)); //QColor saturation is 0-255
|
||||||
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);
|
|
||||||
});
|
|
||||||
return requestId;
|
return requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -569,12 +568,12 @@ QUuid Nanoleaf::setHue(int hue)
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
@ -603,12 +602,12 @@ QUuid Nanoleaf::setBrightness(int percentage)
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
@ -637,12 +636,12 @@ QUuid Nanoleaf::setSaturation(int percentage)
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
request.setHeader(QNetworkRequest::KnownHeaders::ContentTypeHeader, "application/json");
|
||||||
QNetworkReply *reply = m_networkManager->put(request, body.toJson());
|
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] {
|
connect(reply, &QNetworkReply::finished, this, [requestId, reply, this] {
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
@ -684,7 +683,7 @@ QUuid Nanoleaf::setKelvin(int kelvin)
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
@ -709,7 +708,7 @@ void Nanoleaf::getEffects()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -745,7 +744,7 @@ void Nanoleaf::getSelectedEffect()
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
emit connectionChanged(false);
|
emit connectionChanged(false);
|
||||||
return;
|
return;
|
||||||
|
|
@ -778,7 +777,7 @@ QUuid Nanoleaf::setEffect(const QString &effect)
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
|
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);
|
emit requestExecuted(requestId, false);
|
||||||
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
qCWarning(dcNanoleaf()) << "Request error:" << status << reply->errorString();
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,12 @@ public:
|
||||||
QString model;
|
QString model;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ColorMode {
|
||||||
|
EffectMode,
|
||||||
|
HueSaturationMode,
|
||||||
|
ColorTemperatureMode
|
||||||
|
};
|
||||||
|
|
||||||
enum GestureID {
|
enum GestureID {
|
||||||
SingleTap = 0,
|
SingleTap = 0,
|
||||||
DoubleTap = 1,
|
DoubleTap = 1,
|
||||||
|
|
@ -115,10 +121,11 @@ signals:
|
||||||
void authTokenRecieved(const QString &token);
|
void authTokenRecieved(const QString &token);
|
||||||
void powerReceived(bool power);
|
void powerReceived(bool power);
|
||||||
void brightnessReceived(int percentage);
|
void brightnessReceived(int percentage);
|
||||||
void colorModeReceived(const QString &colorMode);
|
void colorModeReceived(ColorMode colorMode);
|
||||||
void hueReceived(int hue);
|
void hueReceived(int hue);
|
||||||
void saturationReceived(int percentage);
|
void saturationReceived(int percentage);
|
||||||
void effectListReceived(const QStringList &effects);
|
void effectListReceived(const QStringList &effects);
|
||||||
|
void colorReceived(QColor color);
|
||||||
void colorTemperatureReceived(int kelvin);
|
void colorTemperatureReceived(int kelvin);
|
||||||
void selectedEffectReceived(const QString &effect);
|
void selectedEffectReceived(const QString &effect);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue