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() {
|
||||
xml2js.parseString(data, function(err, result) {
|
||||
if(!err) {
|
||||
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
||||
xml2js.parseString(list, function(err, result2) {
|
||||
if (!err) {
|
||||
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
||||
for (var i=0; i<devinfo.length; i++) {
|
||||
var light = {
|
||||
"ip": ip,
|
||||
"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 = {
|
||||
if (result["s:Envelope"]) {
|
||||
var list = result["s:Envelope"]["s:Body"][0]["u:GetEndDevicesResponse"][0].DeviceLists[0];
|
||||
xml2js.parseString(list, function(err, result2) {
|
||||
if (!err) {
|
||||
var devinfo = result2.DeviceLists.DeviceList[0].DeviceInfos[0].DeviceInfo;
|
||||
for (var i=0; i<devinfo.length; i++) {
|
||||
var light = {
|
||||
"ip": ip,
|
||||
"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": [],
|
||||
"name": devinfo[i].FriendlyName[0],
|
||||
"id": devinfo[i].DeviceID[0],
|
||||
"capabilities": devinfo[i].CapabilityIDs[0],
|
||||
"state": devinfo[i].CurrentState[0],
|
||||
"type": "light",
|
||||
"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 + "-" + light.id;
|
||||
if (!_wemo.devices[key]){
|
||||
_wemo.devices[key] = light;
|
||||
_wemo.emit('discovered', key);
|
||||
} else {
|
||||
_wemo.devices[key] = light;
|
||||
}
|
||||
}
|
||||
var key = device.serialNumber + "-" + group.id;
|
||||
if (!_wemo.devices[key]) {
|
||||
_wemo.devices[key] = group;
|
||||
_wemo.emit('discovered', key);
|
||||
} else {
|
||||
_wemo.devices[key] = group;
|
||||
var groupinfo = result2.DeviceLists.DeviceList[0].GroupInfos;
|
||||
if (groupinfo) {
|
||||
for(var i=0; i<groupinfo.length; i++) {
|
||||
var group = {
|
||||
"ip": ip,
|
||||
"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",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"description": "Input and Output nodes for Belkin WeMo devices",
|
||||
"repository": "https://github.com/node-red/node-red-nodes/tree/master/hardware",
|
||||
"main": "WeMoNG.js",
|
||||
|
Loading…
Reference in New Issue
Block a user