Skip to content

Commit

Permalink
Fix for type error Issue HealsCodes#6
Browse files Browse the repository at this point in the history
Fixed the way multiple scripts are loaded, fixing the type error in node-red.
  • Loading branch information
Aietes authored Nov 6, 2016
1 parent 2af440e commit 5655325
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions homegear-mqtt.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,45 +169,59 @@
$('#node-input-paramValueList').hide();

$('#node-input-deviceType').hide();

$.getMultiScripts = function(arr, path) {
var _arr = $.map(arr, function(scr) {
return $.getScript( (path||"") + scr );
});

$.getScript('homegear-mqtt/common')
.done(function(data, textStatus, jqxhr) {
$.getScript('homegear-mqtt/families/homematic')
.done(function(data, textStatus, jqxhr) {
$('#node-input-deviceTypeList option').remove();

var deviceTypes = JSON.parse(data);
var deviceOpts = [];

var selected = $('#node-input-deviceType').val();
for(var i in deviceTypes) {
for(var j in deviceTypes[i].names) {
var name = deviceTypes[i].names[j];
var value = i.toString() + ':' + j.toString();
deviceOpts.push([name, value]);
}
_arr.push($.Deferred(function( deferred ){
$( deferred.resolve );
}));

return $.when.apply($, _arr);
};

var script_arr = [
'homegear-mqtt/common',
'homegear-mqtt/families/homematic'
];

$.getMultiScripts(script_arr).done(function(response1, response2) {

$('#node-input-deviceTypeList option').remove();

var deviceTypes = JSON.parse(response2[0]);
var deviceOpts = [];

var selected = $('#node-input-deviceType').val();
for(var i in deviceTypes) {
for(var j in deviceTypes[i].names) {
var name = deviceTypes[i].names[j];
var value = i.toString() + ':' + j.toString();
deviceOpts.push([name, value]);
}
deviceOpts.sort();
for(i = 0; i < deviceOpts.length; ++i) {
var opt = $('<option></option>').val(deviceOpts[i][1])
.text(deviceOpts[i][0]);

opt.appendTo('#node-input-deviceTypeList');
if(selected === opt.val()) {
opt.attr('selected', 'selected');
}
}
deviceOpts.sort();
for(i = 0; i < deviceOpts.length; ++i) {
var opt = $('<option></option>').val(deviceOpts[i][1])
.text(deviceOpts[i][0]);

opt.appendTo('#node-input-deviceTypeList');
if(selected === opt.val()) {
opt.attr('selected', 'selected');
}
}

$('#node-input-deviceTypeList').change(function() {
var value = $('#node-input-deviceTypeList option:selected').val();
var name = $('#node-input-deviceTypeList option:selected').text();
$('#node-input-deviceType').val(value);
$('#node-input-deviceTypeList').change(function() {
var value = $('#node-input-deviceTypeList option:selected').val();
var name = $('#node-input-deviceTypeList option:selected').text();
$('#node-input-deviceType').val(value);

updateDeviceParamLists(deviceTypes[Number(value.split(':')[0])]);
}).show();
updateDeviceParamLists(deviceTypes[Number(value.split(':')[0])]);
}).show();

updateDeviceParamLists(deviceTypes[Number((selected || '0:0').split(':')[0])]);
});
updateDeviceParamLists(deviceTypes[Number((selected || '0:0').split(':')[0])]);
});

function updateDeviceParamLists(device) {
Expand Down

0 comments on commit 5655325

Please sign in to comment.