@@ -696,24 +696,27 @@ function startWizardPhilipsHue(e) {
696696function 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
719722function checkBridgeResult ( reply , usr ) {
@@ -788,25 +791,41 @@ function useGroupId(id) {
788791}
789792
790793async 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
0 commit comments