mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
parent
f2bac89911
commit
2b6661c4f2
@ -100,59 +100,61 @@ WeMoNG.prototype.start = function start() {
|
|||||||
res.on('end',function() {
|
res.on('end',function() {
|
||||||
xml2js.parseString(data, function(err, result) {
|
xml2js.parseString(data, function(err, result) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
if (result["s:Envelope"]) {
|
||||||
xml2js.parseString(list, function(err, result2) {
|
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
||||||
if (!err) {
|
xml2js.parseString(list, function(err, result2) {
|
||||||
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
if (!err) {
|
||||||
for (var i=0; i<devinfo.length; i++) {
|
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
||||||
var light = {
|
for (var i=0; i<devinfo.length; i++) {
|
||||||
"ip": ip,
|
var light = {
|
||||||
"port": port,
|
|
||||||
"udn": device.UDN,
|
|
||||||
"name": devinfo[i].FriendlyName[0],
|
|
||||||
"id": devinfo[i].DeviceID[0],
|
|
||||||
"capabilities": devinfo[i].CapabilityIDs[0],
|
|
||||||
"state": devinfo[i].CurrentState[0],
|
|
||||||
"type": "light",
|
|
||||||
"device": device
|
|
||||||
};
|
|
||||||
var key = device.serialNumber + "-" + light.id;
|
|
||||||
if (!_wemo.devices[key]){
|
|
||||||
_wemo.devices[key] = light;
|
|
||||||
_wemo.emit('discovered', key);
|
|
||||||
} else {
|
|
||||||
_wemo.devices[key] = light;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var groupinfo = result2.DeviceLists.DeviceList[0].GroupInfos;
|
|
||||||
if (groupinfo) {
|
|
||||||
for(var i=0; i<groupinfo.length; i++) {
|
|
||||||
var group = {
|
|
||||||
"ip": ip,
|
"ip": ip,
|
||||||
"port": port,
|
"port": port,
|
||||||
"udn": device.UDN,
|
"udn": device.UDN,
|
||||||
"name": groupinfo[i].GroupInfo[0].GroupName[0],
|
"name": devinfo[i].FriendlyName[0],
|
||||||
"id": groupinfo[i].GroupInfo[0].GroupID[0],
|
"id": devinfo[i].DeviceID[0],
|
||||||
"capabilities": groupinfo[i].GroupInfo[0].GroupCapabilityIDs[0],
|
"capabilities": devinfo[i].CapabilityIDs[0],
|
||||||
"state": groupinfo[i].GroupInfo[0].GroupCapabilityValues[0],
|
"state": devinfo[i].CurrentState[0],
|
||||||
"type": "light group",
|
"type": "light",
|
||||||
"lights": [],
|
|
||||||
"device": device
|
"device": device
|
||||||
}
|
};
|
||||||
for(var j=0; j<groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo.length; j++) {
|
var key = device.serialNumber + "-" + light.id;
|
||||||
group.lights.push(groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo[j].DeviceID[0]);
|
if (!_wemo.devices[key]){
|
||||||
|
_wemo.devices[key] = light;
|
||||||
|
_wemo.emit('discovered', key);
|
||||||
|
} else {
|
||||||
|
_wemo.devices[key] = light;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var key = device.serialNumber + "-" + group.id;
|
var groupinfo = result2.DeviceLists.DeviceList[0].GroupInfos;
|
||||||
if (!_wemo.devices[key]) {
|
if (groupinfo) {
|
||||||
_wemo.devices[key] = group;
|
for(var i=0; i<groupinfo.length; i++) {
|
||||||
_wemo.emit('discovered', key);
|
var group = {
|
||||||
} else {
|
"ip": ip,
|
||||||
_wemo.devices[key] = group;
|
"port": port,
|
||||||
|
"udn": device.UDN,
|
||||||
|
"name": groupinfo[i].GroupInfo[0].GroupName[0],
|
||||||
|
"id": groupinfo[i].GroupInfo[0].GroupID[0],
|
||||||
|
"capabilities": groupinfo[i].GroupInfo[0].GroupCapabilityIDs[0],
|
||||||
|
"state": groupinfo[i].GroupInfo[0].GroupCapabilityValues[0],
|
||||||
|
"type": "light group",
|
||||||
|
"lights": [],
|
||||||
|
"device": device
|
||||||
|
}
|
||||||
|
for(var j=0; j<groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo.length; j++) {
|
||||||
|
group.lights.push(groupinfo[i].GroupInfo[0].DeviceInfos[0].DeviceInfo[j].DeviceID[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var key = device.serialNumber + "-" + group.id;
|
||||||
|
if (!_wemo.devices[key]) {
|
||||||
|
_wemo.devices[key] = group;
|
||||||
|
_wemo.emit('discovered', key);
|
||||||
|
} else {
|
||||||
|
_wemo.devices[key] = group;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-node-wemo",
|
"name": "node-red-node-wemo",
|
||||||
"version": "0.1.8",
|
"version": "0.1.9",
|
||||||
"description": "Input and Output nodes for Belkin WeMo devices",
|
"description": "Input and Output nodes for Belkin WeMo devices",
|
||||||
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
|
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
|
||||||
"main": "WeMoNG.js",
|
"main": "WeMoNG.js",
|
||||||
|
Loading…
Reference in New Issue
Block a user