node-red-contrib-deconz
Advanced tools
Comparing version
@@ -34,3 +34,3 @@ { | ||
}, | ||
"version": "0.1.6" | ||
"version": "0.2.0" | ||
} |
@@ -168,3 +168,2 @@ function deconz_getDeviceMeta(uniqueid) { | ||
if (controller) { | ||
@@ -246,2 +245,65 @@ $.getJSON('/deconz/statelist', { | ||
}); | ||
} | ||
} | ||
function deconz_initSettings(callback) { | ||
$.get("https://dresden-light.appspot.com/discover", function( data ) {}).done(function(data) { | ||
var settings = { | ||
name:data[0].name, | ||
ip:data[0].internalipaddress, | ||
port:data[0].internalport, | ||
apikey:'', | ||
ws_port:'' | ||
}; | ||
$.ajax({ | ||
type: "POST", | ||
dataType: 'json', | ||
url: 'http://'+settings.ip+':'+settings.port+'/api', | ||
data: JSON.stringify({"devicetype":"Node-red"}), | ||
success: function(response){ | ||
var resp = response[0]; | ||
if ('success' in resp) { | ||
settings.apikey = resp.success.username; | ||
$.ajax({ | ||
type: "GET", | ||
dataType: 'json', | ||
url: 'http://'+settings.ip+':'+settings.port+'/api/'+settings.apikey+'/config', | ||
success: function(response){ | ||
if ('websocketport' in response) { | ||
settings.ws_port = response.websocketport; | ||
} | ||
}, | ||
error: function (err) { | ||
var response = (JSON.parse(err.responseText)); | ||
var resp = response[0]; | ||
if ('error' in resp) { | ||
alert(resp.error.description); | ||
} | ||
}, | ||
complete: function() { | ||
callback(settings); | ||
return settings; | ||
} | ||
}); | ||
} | ||
}, | ||
error: function (err) { | ||
var response = (JSON.parse(err.responseText)); | ||
var resp = response[0]; | ||
if ('error' in resp) { | ||
alert(resp.error.description); | ||
} | ||
callback(settings); | ||
return settings; | ||
}, | ||
complete: function() { | ||
} | ||
}); | ||
}).fail(function() { | ||
alert( "Remote server did not answer. Internet problems?" ); | ||
}); | ||
} |
@@ -27,3 +27,19 @@ RED.nodes.registerType('deconz-server', { | ||
return this.name || this.ip+':'+this.port; | ||
} | ||
}, | ||
oneditprepare: function () { | ||
var node = this; | ||
var $refreshBtn = $('#force-refresh'); | ||
$refreshBtn.on('click', function(){ | ||
deconz_initSettings(function(settings){ | ||
$('#node-config-input-name').val(settings.name); | ||
$('#node-config-input-ip').val(settings.ip); | ||
$('#node-config-input-port').val(settings.port); | ||
$('#node-config-input-apikey').val(settings.apikey); | ||
$('#node-config-input-ws_port').val(settings.ws_port); | ||
}); | ||
}); | ||
}, | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
519288
1.86%33
3.13%1932
3.82%