Skip to content

Commit

Permalink
Power on LED device before streaming Identify colors
Browse files Browse the repository at this point in the history
  • Loading branch information
awawa-dev committed Jan 24, 2023
1 parent 947d0b0 commit e9cbced
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 49 deletions.
10 changes: 7 additions & 3 deletions assets/webconfig/js/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class HyperHdrInstance : public QObject

public slots:

void identifyLed(const QJsonObject& params);

bool getReadOnlyMode() { return _readOnlyMode; };

void saveCalibration(QString saveData);
Expand Down
2 changes: 2 additions & 0 deletions include/leddevice/LedDeviceWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 20 additions & 10 deletions sources/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// LedDevice includes
#include <leddevice/LedDeviceWrapper.h>
#include <leddevice/LedDeviceFactory.h>

#include <base/MultiColorAdjustment.h>
#include <base/LinearSmoothing.h>
Expand Down Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions sources/leddevice/LedDeviceWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,10 @@ QJsonObject LedDeviceWrapper::getLedDeviceSchemas()

return result;
}

void LedDeviceWrapper::identifyLed(const QJsonObject& params)
{
QMetaObject::invokeMethod(_ledDevice, [=]() {
_ledDevice->identify(params);
});
}
48 changes: 12 additions & 36 deletions sources/leddevice/dev_net/LedDevicePhilipsHueV2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,42 +1351,18 @@ QJsonObject LedDevicePhilipsHueV2::getProperties(const QJsonObject &params) {
}

void LedDevicePhilipsHueV2::identify(const QJsonObject &params) {
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<int>(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<int>(_handshake_timeout_min);
_devConfig["hs_timeout_max"] = static_cast<int>(_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) {
Expand Down

0 comments on commit e9cbced

Please sign in to comment.