diff --git a/assets/webconfig/js/wizard.js b/assets/webconfig/js/wizard.js index 31ff87535..ca58bec72 100644 --- a/assets/webconfig/js/wizard.js +++ b/assets/webconfig/js/wizard.js @@ -998,8 +998,10 @@ async function discover_hue_bridges() function identify_hue_device(hostAddress, username, id) { - if(useV2Api){ - // flash the channel + if(useV2Api) + { + $('#btn_wiz_save').click(); + // flash the channel let params = { host: hostAddress, clientkey: $('#clientkey').val()||conf_editor.getEditor("root.specificOptions.clientkey")?.getValue(), @@ -1008,7 +1010,9 @@ function identify_hue_device(hostAddress, username, id) channelId: id }; requestLedDeviceIdentification("philipshuev2", params); - }else{ + } + else + { let params = { host: hostAddress, user: username, lightId: id }; requestLedDeviceIdentification("philipshue", params); } diff --git a/include/base/HyperHdrInstance.h b/include/base/HyperHdrInstance.h index 4f9e2ea5c..b5e16221a 100644 --- a/include/base/HyperHdrInstance.h +++ b/include/base/HyperHdrInstance.h @@ -109,6 +109,8 @@ class HyperHdrInstance : public QObject public slots: + void identifyLed(const QJsonObject& params); + bool getReadOnlyMode() { return _readOnlyMode; }; void saveCalibration(QString saveData); diff --git a/include/leddevice/LedDeviceWrapper.h b/include/leddevice/LedDeviceWrapper.h index 9bb551bc2..a5d4c692a 100644 --- a/include/leddevice/LedDeviceWrapper.h +++ b/include/leddevice/LedDeviceWrapper.h @@ -61,6 +61,8 @@ class LedDeviceWrapper : public QObject /// unsigned int getLedCount() const; + void identifyLed(const QJsonObject& params); + public slots: /// /// @brief Handle new component state request diff --git a/sources/api/JsonAPI.cpp b/sources/api/JsonAPI.cpp index fe51f8939..0ca94d168 100644 --- a/sources/api/JsonAPI.cpp +++ b/sources/api/JsonAPI.cpp @@ -1667,9 +1667,19 @@ void JsonAPI::handleLedDeviceCommand(const QJsonObject& message, const QString& } else if (subc == "identify") { - ledDevice = LedDeviceFactory::construct(config); const QJsonObject& params = message["params"].toObject(); - ledDevice->identify(params); + + if (devType == "philipshuev2") + { + QMetaObject::invokeMethod(_hyperhdr, [=]() { + _hyperhdr->identifyLed(params); + }); + } + else + { + auto ledDevice = LedDeviceFactory::construct(config); + ledDevice->identify(params); + } sendSuccessReply(full_command, tan); } @@ -1897,7 +1907,7 @@ void JsonAPI::handleTunnel(const QJsonObject& message, const QString& command, i if (service == "hue") { - QUrl tempUrl("http://"+ip); + QUrl tempUrl("http://"+ip); if ((path.indexOf("/clip/v2") != 0 && path.indexOf("/api") != 0) || ip.indexOf("/") >= 0) { sendErrorReply("Invalid path", full_command, tan); @@ -1922,13 +1932,13 @@ void JsonAPI::handleTunnel(const QJsonObject& message, const QString& command, i sendErrorReply("The Philips Hue wizard supports only valid IP addresses in the LOCAL network.\nIt may be preferable to use the IP4 address instead of the host name if you are having problems with DNS resolution.", full_command, tan); return; } - httpResponse result; - const QJsonObject &headerObject = message["header"].toObject(); - if(!headerObject.isEmpty()){ - for (const auto &item: headerObject.keys()){ - provider.addHeader(item,headerObject[item].toString()); - } - } + httpResponse result; + const QJsonObject &headerObject = message["header"].toObject(); + if(!headerObject.isEmpty()){ + for (const auto &item: headerObject.keys()){ + provider.addHeader(item,headerObject[item].toString()); + } + } if (subcommand == "put") result = provider.put(url, data); diff --git a/sources/base/HyperHdrInstance.cpp b/sources/base/HyperHdrInstance.cpp index f4e1261d1..00c8188a3 100644 --- a/sources/base/HyperHdrInstance.cpp +++ b/sources/base/HyperHdrInstance.cpp @@ -21,6 +21,7 @@ // LedDevice includes #include +#include #include #include @@ -765,3 +766,8 @@ QString HyperHdrInstance::deleteEffect(const QString& effectName) } +void HyperHdrInstance::identifyLed(const QJsonObject& params) +{ + _ledDeviceWrapper->handleComponentState(hyperhdr::Components::COMP_LEDDEVICE, true); + _ledDeviceWrapper->identifyLed(params); +} diff --git a/sources/leddevice/LedDeviceWrapper.cpp b/sources/leddevice/LedDeviceWrapper.cpp index 28b264531..2d1014543 100644 --- a/sources/leddevice/LedDeviceWrapper.cpp +++ b/sources/leddevice/LedDeviceWrapper.cpp @@ -187,3 +187,10 @@ QJsonObject LedDeviceWrapper::getLedDeviceSchemas() return result; } + +void LedDeviceWrapper::identifyLed(const QJsonObject& params) +{ + QMetaObject::invokeMethod(_ledDevice, [=]() { + _ledDevice->identify(params); + }); +} diff --git a/sources/leddevice/dev_net/LedDevicePhilipsHueV2.cpp b/sources/leddevice/dev_net/LedDevicePhilipsHueV2.cpp index df9717422..b4b68383f 100644 --- a/sources/leddevice/dev_net/LedDevicePhilipsHueV2.cpp +++ b/sources/leddevice/dev_net/LedDevicePhilipsHueV2.cpp @@ -1351,42 +1351,18 @@ QJsonObject LedDevicePhilipsHueV2::getProperties(const QJsonObject ¶ms) { } void LedDevicePhilipsHueV2::identify(const QJsonObject ¶ms) { - Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData()); - QJsonObject properties; - - // Identify Phillips-Bridge device - QString host = params["host"].toString(""); - if (!host.isEmpty()) { - unsigned int channelId = params["channelId"].toInt(0); - QString username=params["user"].toString(""); - _entertainmentConfigurationId = params["entertainmentConfigurationId"].toString(""); - _useHueEntertainmentAPI=true; - QUrl tempUrl("http://" + host); - QString apiHost = tempUrl.host(); - _devConfig["host"] = apiHost; - _devConfig["sslport"] = API_SSL_SERVER_PORT; - _devConfig["servername"] = API_SSL_SERVER_NAME; - _devConfig["refreshTime"] = static_cast(STREAM_REFRESH_TIME.count()); - _devConfig["psk"] = params[CONFIG_CLIENTKEY].toString(); - _devConfig["psk_identity"] = username; - _devConfig["seed_custom"] = API_SSL_SEED_CUSTOM; - _devConfig["retry_left"] = _maxRetry; - _devConfig["hs_attempts"] = STREAM_SSL_HANDSHAKE_ATTEMPTS; - _devConfig["hs_timeout_min"] = static_cast(_handshake_timeout_min); - _devConfig["hs_timeout_max"] = static_cast(_handshake_timeout_max); - initRestAPI(apiHost, API_DEFAULT_PORT, username); - setApplicationId(); - ProviderUdpSSL::init(_devConfig); - - _channels.clear(); - _channels.emplace_back(_log, channelId, QJsonObject(), QStringList(), channelId); - _isInitLeds= true; - openStream(); - colorChannel(ColorRgb::RED, channelId); - colorChannel(ColorRgb::GREEN, channelId); - colorChannel(ColorRgb::BLUE, channelId); - stopStream(); - } + Debug(_log, "Device: [%s], params: [%s]", (_isOn) ? "ON" : "OFF", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData()); + if (_isOn) + { + auto channelsBackup = _channels; + unsigned int channelId = params["channelId"].toInt(0); + _channels.clear(); + _channels.emplace_back(_log, channelId, QJsonObject(), QStringList(), channelId); + colorChannel(ColorRgb::RED, channelId); + colorChannel(ColorRgb::GREEN, channelId); + colorChannel(ColorRgb::BLUE, channelId); + _channels = channelsBackup; + } } void LedDevicePhilipsHueV2::colorChannel(const ColorRgb &colorRgb, unsigned int i) {