I found when parsing elements in XML objects:
var varElement = XML.parse(data);
varElement.elements.forEach(function (node) {
var curid = node.attributes.id;
var varname = node.attributes.name;
if there is no elements it errors out with a null and causes issues.
I tried using:
if (varElement.elements.length > 0) {
but didnt help.
I think the error happens when calling the parse. Is there a way to do this without causing and error? or Is it just as good using a TRY ERR ROUTINE:
try {
var varElement = XML.parse(data);
varElement.elements.forEach(function (node) {
var curid = node.attributes.id;
var varname = node.attributes.name;
var pluginDevice = new Device();
pluginDevice.Id = "ISYState" + curid;
//pluginDevice.Name = "ISYState_" + varname;
pluginDevice.DisplayName = "ISYState_" + varname;
pluginDevice.Icon = "var.png";
pluginDevice.DeviceType = "ISYStateVariable";
pluginDevice.TileTemplate = "ISYStateVariableTile.xaml";
pluginDevice.DetailsTemplate = "";
pluginDevice.Capabilities = [];
pluginDevice.Attributes = ["ISYStateValue", "timeSet"];
plugin.Devices[pluginDevice.Id] = pluginDevice;
});
} catch(err) {log("No State Variables");}
}
Just want to follow best script protocol.