From d3a912f014b12ce443516a6d8a78734228da7c8e Mon Sep 17 00:00:00 2001 From: LordGrey <48840279+Lord-Grey@users.noreply.github.com> Date: Sat, 31 Jul 2021 20:57:08 +0200 Subject: [PATCH] Fix #1276 (#1279) --- assets/webconfig/js/wizard.js | 77 +++++++++++++-------- libsrc/leddevice/dev_net/ProviderUdpSSL.cpp | 17 +++-- 2 files changed, 59 insertions(+), 35 deletions(-) diff --git a/assets/webconfig/js/wizard.js b/assets/webconfig/js/wizard.js index f9eb5992..3f8ee564 100755 --- a/assets/webconfig/js/wizard.js +++ b/assets/webconfig/js/wizard.js @@ -696,24 +696,27 @@ function startWizardPhilipsHue(e) { function checkHueBridge(cb, hueUser) { var usr = (typeof hueUser != "undefined") ? hueUser : 'config'; if (usr == 'config') $('#wiz_hue_discovered').html(""); - $.ajax({ - url: 'http://' + hueIPs[hueIPsinc].internalipaddress + '/api/' + usr, - type: "GET", - dataType: "json", - success: function (json) { - if (json.config) { - cb(true, usr); - } else if (json.name && json.bridgeid && json.modelid) { - $('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion); - cb(true); - } else { - cb(false); - } - }, - timeout: 2500 - }).fail(function () { - cb(false); - }); + + if (hueIPs[hueIPsinc]) { + $.ajax({ + url: 'http://' + hueIPs[hueIPsinc].internalipaddress + '/api/' + usr, + type: "GET", + dataType: "json", + success: function (json) { + if (json.config) { + cb(true, usr); + } else if (json.name && json.bridgeid && json.modelid) { + $('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion); + cb(true); + } else { + cb(false); + } + }, + timeout: 2500 + }).fail(function () { + cb(false); + }); + } } function checkBridgeResult(reply, usr) { @@ -788,25 +791,41 @@ function useGroupId(id) { } async function discover_hue_bridges() { + $('#wiz_hue_ipstate').html($.i18n('edt_dev_spec_devices_discovery_inprogress')); + $('#wiz_hue_discovered').html("") const res = await requestLedDeviceDiscovery('philipshue'); // TODO: error case unhandled // res can be: false (timeout) or res.error (not found) if (res && !res.error) { const r = res.info; - + // Process devices returned by discovery - if (r.devices.length == 0) + if (r.devices.length == 0) { $('#wiz_hue_ipstate').html($.i18n('wiz_hue_failure_ip')); + $('#wiz_hue_discovered').html("") + } else { for (const device of r.devices) { - console.log("Device:", device); + //console.log("Device:", device); + if (device && device.ip && device.port) { - var ip = device.hostname + ":" + device.port; - console.log("Host:", ip); + var ip; + if (device.hostname && device.domain) { + ip = device.hostname + "." + device.domain + ":" + device.port; + } else { + ip = device.ip + ":" + device.port; + } - hueIPs.push({ internalipaddress: ip }); + if (ip) { + + if (!hueIPs.some(item => item.internalipaddress === ip)) { + hueIPs.push({ internalipaddress: ip }); + } + } + } } + var usr = $('#user').val(); if (usr != "") { checkHueBridge(checkUserResult, usr); @@ -884,12 +903,12 @@ function beginWizardHue() { } } //check if ip is empty/reachable/search for bridge - if (eV("output") == "") { + if (eV("host") == "") { //getHueIPs(); discover_hue_bridges(); } else { - var ip = eV("output"); + var ip = eV("host"); $('#ip').val(ip); hueIPs.unshift({ internalipaddress: ip }); if (usr != "") { @@ -954,7 +973,7 @@ function beginWizardHue() { //Start with a clean configuration var d = {}; - d.output = $('#ip').val(); + d.host = $('#ip').val(); d.username = $('#user').val(); d.type = 'philipshue'; d.colorOrder = 'rgb'; @@ -1534,7 +1553,7 @@ function beginWizardAtmoOrb() { configuredLights = configruedOrbIds.split(",").map(Number); } - var multiCastGroup = conf_editor.getEditor("root.specificOptions.output").getValue(); + var multiCastGroup = conf_editor.getEditor("root.specificOptions.host").getValue(); var multiCastPort = parseInt(conf_editor.getEditor("root.specificOptions.port").getValue()); discover_atmoorb_lights(multiCastGroup, multiCastPort); @@ -1576,7 +1595,7 @@ function beginWizardAtmoOrb() { d.orbIds = finalLights.toString(); d.useOrbSmoothing = (eV("useOrbSmoothing") == true); - d.output = conf_editor.getEditor("root.specificOptions.output").getValue(); + d.host = conf_editor.getEditor("root.specificOptions.host").getValue(); d.port = parseInt(conf_editor.getEditor("root.specificOptions.port").getValue()); d.latchTime = parseInt(conf_editor.getEditor("root.specificOptions.latchTime").getValue());; diff --git a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp index cfdfde80..244cdb3f 100644 --- a/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp +++ b/libsrc/leddevice/dev_net/ProviderUdpSSL.cpp @@ -11,6 +11,7 @@ // Local Hyperion includes #include "ProviderUdpSSL.h" +#include const int MAX_RETRY = 5; const ushort MAX_PORT_SSL = 65535; @@ -73,6 +74,10 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig) if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5); QString host = deviceConfig["host"].toString(_defaultHost); + //Split hostname from API-port in case given + QStringList addressparts = QStringUtils::split(host, ":", QStringUtils::SplitBehavior::SkipEmptyParts); + QString udpHost = addressparts[0]; + QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose"; configLog( "SSL Streamer Debug", "%s", ( _debugStreamer ) ? "yes" : "no" ); @@ -91,24 +96,24 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig) configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max ); configLog( "SSL Handshake attempts", "%d", _handshake_attempts ); - if ( _address.setAddress(host) ) + if ( _address.setAddress(udpHost) ) { - Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR( host ) ); + Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR(udpHost) ); } else { - Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR( host ) ); - QHostInfo info = QHostInfo::fromName(host); + Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR(udpHost) ); + QHostInfo info = QHostInfo::fromName(udpHost); if ( info.addresses().isEmpty() ) { - Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR( host ) ); + Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR(udpHost) ); QString errortext = QString("Invalid target address [%1]!").arg(host); this->setInError( errortext ); isInitOK = false; } else { - Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR( host ) ); + Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR(udpHost) ); _address = info.addresses().first(); } }