node-red-contrib-deconz
Advanced tools
Comparing version 0.10.7 to 0.11.0
@@ -42,8 +42,3 @@ var request = require('request'); | ||
if (controller && controller.constructor.name === "ServerNode") { | ||
if (config.uniqueid.match(/^group_/)) { | ||
var groupid = ((config.uniqueid).split('group_').join('')); | ||
var item = controller.getGroup(groupid); | ||
} else { | ||
var item = controller.getDevice(config.uniqueid); | ||
} | ||
var item = controller.getDevice(config.uniqueid); | ||
if (item) { | ||
@@ -50,0 +45,0 @@ res.json(item.state); |
@@ -14,3 +14,20 @@ module.exports = function(RED) { | ||
if (node.server) { | ||
if (typeof (node.config.device) == 'string' && node.config.device.length) { | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
if (deviceMeta !== undefined && deviceMeta && "uniqueid" in deviceMeta) { | ||
node.server.devices[node.id] = deviceMeta.uniqueid; //regisgter node in devices list | ||
} else { | ||
node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'Error' | ||
}); | ||
} | ||
} else { | ||
node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'device not set' | ||
}); | ||
} | ||
} else { | ||
@@ -29,10 +46,4 @@ node.status({ | ||
clearTimeout(node.cleanTimer); | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
if ((/group_/g).test(node.config.device)) { | ||
var groupid = ((node.config.device).split('group_').join('')); | ||
var deviceMeta = node.server.getGroup(groupid); | ||
} else { | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
} | ||
if (deviceMeta) { | ||
@@ -39,0 +50,0 @@ node.server.devices[node.id] = deviceMeta.uniqueid; |
@@ -18,4 +18,2 @@ module.exports = function(RED) { | ||
node.server.on('onNewDevice', (uniqueid) => this.onNewDevice(uniqueid)); | ||
node.sendLastState(); | ||
} else { | ||
@@ -300,2 +298,3 @@ node.status({ | ||
var node = this; | ||
node.sendLastState(); | ||
} | ||
@@ -302,0 +301,0 @@ |
@@ -76,2 +76,12 @@ var request = require('request'); | ||
case 'toggle': | ||
command = "on"; | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
if (deviceMeta !== undefined && deviceMeta && "state" in deviceMeta && "on" in deviceMeta.state) { | ||
payload = !deviceMeta.state.on; | ||
} else { | ||
payload = false; | ||
} | ||
break; | ||
case 'bri': | ||
@@ -113,53 +123,30 @@ case 'hue': | ||
//send data to API | ||
if ((/group_/g).test(node.config.device)) { | ||
var groupid = ((node.config.device).split('group_').join('')); | ||
var group = node.server.getGroup(groupid); | ||
if (group !== false) { | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
if (deviceMeta !== undefined && deviceMeta && "device_id" in deviceMeta) { | ||
if ((/group_/g).test(node.config.device)) { | ||
var groupid = ((node.config.device).split('group_').join('')); | ||
var url = 'http://' + node.server.ip + ':' + node.server.port + '/api/' + node.server.apikey + '/groups/' + groupid + '/action'; | ||
var post = {}; | ||
if (node.commandType == 'object' || node.commandType == 'homekit') { | ||
post = payload; | ||
} else { | ||
if (command != 'on') post['on'] = true; | ||
if (command == 'bri') post['on'] = payload > 0 ? true : false; | ||
post[command] = payload; | ||
} | ||
node.postData(url, post); | ||
} else { | ||
node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'no device' | ||
}); | ||
node.cleanTimer = setTimeout(function(){ | ||
node.status({}); //clean | ||
}, 3000); | ||
var url = 'http://' + node.server.ip + ':' + node.server.port + '/api/' + node.server.apikey + '/lights/' + deviceMeta.device_id + '/state'; | ||
} | ||
var post = {}; | ||
if (node.commandType == 'object' || node.commandType == 'homekit') { | ||
post = payload; | ||
} else { | ||
if (command != 'on') post['on'] = true; | ||
if (command == 'bri') post['on'] = payload > 0 ? true : false; | ||
post[command] = payload; | ||
} | ||
node.postData(url, post); | ||
} else { | ||
node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'no device' | ||
}); | ||
node.cleanTimer = setTimeout(function(){ | ||
node.status({}); //clean | ||
}, 3000); | ||
var deviceMeta = node.server.getDevice(node.config.device); | ||
if (deviceMeta !== undefined && deviceMeta && "device_id" in deviceMeta) { | ||
var url = 'http://' + node.server.ip + ':' + node.server.port + '/api/' + node.server.apikey + '/lights/' + deviceMeta.device_id + '/state'; | ||
var post = {}; | ||
if (node.commandType == 'object' || node.commandType == 'homekit') { | ||
post = payload; | ||
} else { | ||
if (command != 'on') post['on'] = true; | ||
if (command == 'bri') post['on'] = payload > 0 ? true : false; | ||
post[command] = payload; | ||
} | ||
node.postData(url, post); | ||
} else { | ||
node.status({ | ||
fill: "red", | ||
shape: "dot", | ||
text: 'no device' | ||
}); | ||
node.cleanTimer = setTimeout(function(){ | ||
node.status({}); //clean | ||
}, 3000); | ||
} | ||
} | ||
@@ -166,0 +153,0 @@ }); |
@@ -11,3 +11,2 @@ var request = require('request'); | ||
node.items = undefined; | ||
node.groups = undefined; | ||
node.items_list = undefined; | ||
@@ -22,2 +21,3 @@ node.discoverProcess = false; | ||
node.devices = {}; | ||
node.setMaxListeners(255); | ||
@@ -27,4 +27,2 @@ node.refreshDiscoverTimer = null; | ||
node.socket = new DeconzSocket({ | ||
@@ -36,3 +34,2 @@ hostname: this.ip, | ||
node.socket.on('close', (code, reason) => this.onSocketClose(code, reason)); | ||
@@ -111,4 +108,14 @@ node.socket.on('unauthorized', () => this.onSocketUnauthorized()); | ||
if ("groups" in dataParsed) { | ||
node.groups = dataParsed.groups; | ||
for (var index in dataParsed.groups) { | ||
var prop = dataParsed.groups[index]; | ||
prop.device_type = 'groups'; | ||
var groupid = "group_" + parseInt(index); | ||
prop.device_id = groupid; | ||
prop.uniqueid = groupid; | ||
if (node.oldItemsList !== undefined && prop.uniqueid in node.oldItemsList) {} else { | ||
node.items[prop.uniqueid] = prop; | ||
node.emit("onNewDevice", prop.uniqueid); | ||
} | ||
node.items[prop.uniqueid] = prop; | ||
} | ||
@@ -148,13 +155,2 @@ } | ||
getGroup(groupid) { | ||
var node = this; | ||
var result = false; | ||
if (node.groups !== undefined && groupid in node.groups) { | ||
result = node.groups[groupid]; | ||
} | ||
return result; | ||
} | ||
getItemsList(callback, forceRefresh = false) { | ||
@@ -174,3 +170,3 @@ var node = this; | ||
callback(node.items_list, node.groups); | ||
callback(node.items_list); | ||
return node.items_list; | ||
@@ -226,8 +222,13 @@ }, forceRefresh); | ||
if (dataParsed.r == "scenes") { return; } | ||
if (dataParsed.r == "groups") { | ||
dataParsed.uniqueid = "group_" + dataParsed.id; | ||
} | ||
for (var nodeId in this.devices) { | ||
var item = this.devices[nodeId]; | ||
var node = RED.nodes.getNode(nodeId); | ||
if (dataParsed.uniqueid === item) { | ||
var node = RED.nodes.getNode(nodeId); | ||
if (node && "server" in node) { | ||
@@ -234,0 +235,0 @@ //update server items db |
@@ -41,3 +41,3 @@ { | ||
}, | ||
"version": "0.10.7" | ||
"version": "0.11.0" | ||
} |
@@ -33,3 +33,3 @@ function deconz_gatewayScanner(nodeItem, selectedItemElementName, options = {}) { | ||
if (options.allowEmpty) { | ||
selectedItemElement.html('<option value="">--Select device</option>'); | ||
selectedItemElement.html('<option value="" disabled selected>Select device</option>'); | ||
} | ||
@@ -42,11 +42,36 @@ | ||
var groupHtml = ''; | ||
var prevName = ''; | ||
var itemList = []; | ||
var groupList = []; | ||
$.each(data.items, function(index, value) { | ||
if (value.meta.device_type === "groups") { | ||
groupList.push(value) | ||
} else { | ||
itemList.push(value) | ||
} | ||
}); | ||
var itemsByName = itemList.slice(0); | ||
if ( groupList.length > 0 ) { | ||
var groupsByName = groupList.slice(0); | ||
groupsByName.sort(function(a,b) { | ||
var x = a.device_name.toLowerCase(); | ||
var y = b.device_name.toLowerCase(); | ||
return x < y ? -1 : x > y ? 1 : 0; | ||
}); | ||
} | ||
itemsByName.sort(function(a,b) { | ||
var x = a.device_name.toLowerCase(); | ||
var y = b.device_name.toLowerCase(); | ||
return x < y ? -1 : x > y ? 1 : 0; | ||
}); | ||
if (options.groups && data.groups) { | ||
groupHtml = $('<optgroup/>', { label: "Groups" }); | ||
if (options.groups && groupsByName) { | ||
groupHtml = $('<optgroup/>', { label: "Light Groups" }); | ||
groupHtml.appendTo(selectedItemElement); | ||
$.each(data.groups, function(index, value) { | ||
$('<option value="group_' + value.id +'">' +value.name +' (lights: '+value.lights.length+')</option>').appendTo(groupHtml); | ||
$.each(groupsByName, function(index, value) { | ||
if (value.meta.device_type == "groups") { | ||
$('<option value="group_' + value.meta.id +'">○ ' +value.meta.name +' (lights: '+value.meta.lights.length+')</option>').appendTo(groupHtml); | ||
} | ||
}); | ||
@@ -58,3 +83,3 @@ | ||
$.each(data.items, function(index, value) { | ||
$.each(itemsByName, function(index, value) { | ||
disabled = ''; | ||
@@ -69,4 +94,4 @@ nameSuffix = ''; | ||
(!("meta" in value) | ||
|| !("config" in value.meta) | ||
|| !("battery" in value.meta.config) | ||
|| !("config" in value.meta) | ||
|| !("battery" in value.meta.config) | ||
) | ||
@@ -109,5 +134,5 @@ ) { | ||
// $('<option value="' + value.topic + '"'+(selected ? 'selected' : '')+'>' + value.control_name + '</option>').appendTo(groupHtml); | ||
var parentElement = (options.groups && data.groups.length)?groupHtml:selectedItemElement; | ||
$('<option '+disabled+' value="' + value.uniqueid +'">' +value.device_name + (nameSuffix?' ('+nameSuffix+')':'') +'</option>').appendTo(parentElement); | ||
//var name = (value.device_name).split(':',2); | ||
var parentElement = (options.groups)?groupHtml:selectedItemElement; | ||
$('<option'+ disabled+' value="' + value.uniqueid +'">● ' + value.device_name + (nameSuffix?' ('+nameSuffix+')':'') +'</option>').appendTo(parentElement); | ||
}); | ||
@@ -406,2 +431,10 @@ | ||
} | ||
} | ||
function deconz_filterDeviceName(name) { | ||
var result = name.replace(/ *\([^)]*\) */g, ""); //remove (lights: 1) | ||
result = result.replace(new RegExp('●', 'g'), ''); | ||
result = result.trim(); | ||
return result; | ||
} |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
769524
2783