Skip to content

Commit d3a912f

Browse files
authored
Fix #1276 (#1279)
1 parent d3c8e6d commit d3a912f

File tree

2 files changed

+59
-35
lines changed

2 files changed

+59
-35
lines changed

assets/webconfig/js/wizard.js

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -696,24 +696,27 @@ function startWizardPhilipsHue(e) {
696696
function checkHueBridge(cb, hueUser) {
697697
var usr = (typeof hueUser != "undefined") ? hueUser : 'config';
698698
if (usr == 'config') $('#wiz_hue_discovered').html("");
699-
$.ajax({
700-
url: 'http://' + hueIPs[hueIPsinc].internalipaddress + '/api/' + usr,
701-
type: "GET",
702-
dataType: "json",
703-
success: function (json) {
704-
if (json.config) {
705-
cb(true, usr);
706-
} else if (json.name && json.bridgeid && json.modelid) {
707-
$('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion);
708-
cb(true);
709-
} else {
710-
cb(false);
711-
}
712-
},
713-
timeout: 2500
714-
}).fail(function () {
715-
cb(false);
716-
});
699+
700+
if (hueIPs[hueIPsinc]) {
701+
$.ajax({
702+
url: 'http://' + hueIPs[hueIPsinc].internalipaddress + '/api/' + usr,
703+
type: "GET",
704+
dataType: "json",
705+
success: function (json) {
706+
if (json.config) {
707+
cb(true, usr);
708+
} else if (json.name && json.bridgeid && json.modelid) {
709+
$('#wiz_hue_discovered').html("Bridge: " + json.name + ", Modelid: " + json.modelid + ", API-Version: " + json.apiversion);
710+
cb(true);
711+
} else {
712+
cb(false);
713+
}
714+
},
715+
timeout: 2500
716+
}).fail(function () {
717+
cb(false);
718+
});
719+
}
717720
}
718721

719722
function checkBridgeResult(reply, usr) {
@@ -788,25 +791,41 @@ function useGroupId(id) {
788791
}
789792

790793
async function discover_hue_bridges() {
794+
$('#wiz_hue_ipstate').html($.i18n('edt_dev_spec_devices_discovery_inprogress'));
795+
$('#wiz_hue_discovered').html("")
791796
const res = await requestLedDeviceDiscovery('philipshue');
792797

793798
// TODO: error case unhandled
794799
// res can be: false (timeout) or res.error (not found)
795800
if (res && !res.error) {
796801
const r = res.info;
797-
802+
798803
// Process devices returned by discovery
799-
if (r.devices.length == 0)
804+
if (r.devices.length == 0) {
800805
$('#wiz_hue_ipstate').html($.i18n('wiz_hue_failure_ip'));
806+
$('#wiz_hue_discovered').html("")
807+
}
801808
else {
802809
for (const device of r.devices) {
803-
console.log("Device:", device);
810+
//console.log("Device:", device);
811+
if (device && device.ip && device.port) {
812+
813+
var ip;
814+
if (device.hostname && device.domain) {
815+
ip = device.hostname + "." + device.domain + ":" + device.port;
816+
} else {
817+
ip = device.ip + ":" + device.port;
818+
}
804819

805-
var ip = device.hostname + ":" + device.port;
806-
console.log("Host:", ip);
820+
if (ip) {
807821

808-
hueIPs.push({ internalipaddress: ip });
822+
if (!hueIPs.some(item => item.internalipaddress === ip)) {
823+
hueIPs.push({ internalipaddress: ip });
824+
}
825+
}
826+
}
809827
}
828+
810829
var usr = $('#user').val();
811830
if (usr != "") {
812831
checkHueBridge(checkUserResult, usr);
@@ -884,12 +903,12 @@ function beginWizardHue() {
884903
}
885904
}
886905
//check if ip is empty/reachable/search for bridge
887-
if (eV("output") == "") {
906+
if (eV("host") == "") {
888907
//getHueIPs();
889908
discover_hue_bridges();
890909
}
891910
else {
892-
var ip = eV("output");
911+
var ip = eV("host");
893912
$('#ip').val(ip);
894913
hueIPs.unshift({ internalipaddress: ip });
895914
if (usr != "") {
@@ -954,7 +973,7 @@ function beginWizardHue() {
954973

955974
//Start with a clean configuration
956975
var d = {};
957-
d.output = $('#ip').val();
976+
d.host = $('#ip').val();
958977
d.username = $('#user').val();
959978
d.type = 'philipshue';
960979
d.colorOrder = 'rgb';
@@ -1534,7 +1553,7 @@ function beginWizardAtmoOrb() {
15341553
configuredLights = configruedOrbIds.split(",").map(Number);
15351554
}
15361555

1537-
var multiCastGroup = conf_editor.getEditor("root.specificOptions.output").getValue();
1556+
var multiCastGroup = conf_editor.getEditor("root.specificOptions.host").getValue();
15381557
var multiCastPort = parseInt(conf_editor.getEditor("root.specificOptions.port").getValue());
15391558

15401559
discover_atmoorb_lights(multiCastGroup, multiCastPort);
@@ -1576,7 +1595,7 @@ function beginWizardAtmoOrb() {
15761595
d.orbIds = finalLights.toString();
15771596
d.useOrbSmoothing = (eV("useOrbSmoothing") == true);
15781597

1579-
d.output = conf_editor.getEditor("root.specificOptions.output").getValue();
1598+
d.host = conf_editor.getEditor("root.specificOptions.host").getValue();
15801599
d.port = parseInt(conf_editor.getEditor("root.specificOptions.port").getValue());
15811600
d.latchTime = parseInt(conf_editor.getEditor("root.specificOptions.latchTime").getValue());;
15821601

libsrc/leddevice/dev_net/ProviderUdpSSL.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
// Local Hyperion includes
1313
#include "ProviderUdpSSL.h"
14+
#include <utils/QStringUtils.h>
1415

1516
const int MAX_RETRY = 5;
1617
const ushort MAX_PORT_SSL = 65535;
@@ -73,6 +74,10 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
7374
if( deviceConfig.contains("hs_attempts") ) _handshake_attempts = deviceConfig["hs_attempts"].toInt(5);
7475

7576
QString host = deviceConfig["host"].toString(_defaultHost);
77+
//Split hostname from API-port in case given
78+
QStringList addressparts = QStringUtils::split(host, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
79+
QString udpHost = addressparts[0];
80+
7681
QStringList debugLevels = QStringList() << "No Debug" << "Error" << "State Change" << "Informational" << "Verbose";
7782

7883
configLog( "SSL Streamer Debug", "%s", ( _debugStreamer ) ? "yes" : "no" );
@@ -91,24 +96,24 @@ bool ProviderUdpSSL::init(const QJsonObject &deviceConfig)
9196
configLog( "SSL Handshake Timeout max", "%d", _handshake_timeout_max );
9297
configLog( "SSL Handshake attempts", "%d", _handshake_attempts );
9398

94-
if ( _address.setAddress(host) )
99+
if ( _address.setAddress(udpHost) )
95100
{
96-
Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR( host ) );
101+
Debug( _log, "Successfully parsed %s as an ip address.", QSTRING_CSTR(udpHost) );
97102
}
98103
else
99104
{
100-
Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR( host ) );
101-
QHostInfo info = QHostInfo::fromName(host);
105+
Debug( _log, "Failed to parse [%s] as an ip address.", QSTRING_CSTR(udpHost) );
106+
QHostInfo info = QHostInfo::fromName(udpHost);
102107
if ( info.addresses().isEmpty() )
103108
{
104-
Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR( host ) );
109+
Debug( _log, "Failed to parse [%s] as a hostname.", QSTRING_CSTR(udpHost) );
105110
QString errortext = QString("Invalid target address [%1]!").arg(host);
106111
this->setInError( errortext );
107112
isInitOK = false;
108113
}
109114
else
110115
{
111-
Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR( host ) );
116+
Debug( _log, "Successfully parsed %s as a hostname.", QSTRING_CSTR(udpHost) );
112117
_address = info.addresses().first();
113118
}
114119
}

0 commit comments

Comments
 (0)