htd-lync
Version:
This library is meant to be used to interact with an HTD Lync 12
150 lines (128 loc) • 3.4 kB
JavaScript
var systems = JSON.parse(localStorage.getItem('systems'));
var uuid = localStorage.getItem('system');
uuid = uuid.replace('"', "");
uuid = uuid.replace('"', "");
var systemIdx = 0;
console.log("UUID: " + uuid)
for (i = 0; i < systems.length; i++) {
console.log(systems[i].system.uuid);
if (uuid == systems[i].system.uuid) {
console.log("system match")
systemIdx = i;
}
}
var Gzone;
var Gsource;
var Ggroup;
var customShortcuts = {
0: "",
1: "",
2: "",
3: ""
}
if (!systems) {
systems = [];
}
for (i = 0; i < systems.length; i++) {
console.log("system", systems[i]);
//console.log(system);
if (!systems[i] || !systems[i].system) {
console.log("no systems")
} else if (systems[i].system.uuid == uuid) {
console.log("uuid match")
Gzone = systems[i].Gzone;
Gsource = systems[i].Gsource;
Ggroup = systems[i].Ggroup;
//presets = systems[i].presets;
// shortcuts = systems[i].shortcuts;
//sources = systems[i].sources;
//zones = systems[i].zones;
//groups = systems[i].groups;
enableDoorbell = systems[i].enableDoorbell;
// if (systems[i].customShortcuts) {
// customShortcuts = systems[i].customShortcuts;
//
// }
}
}
if (!systems[systemIdx].system.defaultGroup) {
systems[systemIdx].system.defaultGroup = 0;
}
if (!Gzone) {
Gzone = 1;
}
if (!Gsource) {
Gsource = 1;
}
if (!Ggroup) {
Ggroup = 0;
}
if (!systems[systemIdx].shortcuts) {
systems[systemIdx].shortcuts = {
0: 0,
1: 0,
2: 0,
3: 0
};
}
var appIcons = [];
//var groups = JSON.parse(localStorage.getItem('groups'));
function updateData() {
console.log("update data");
var loaded = false;
if (systems.length == 0) {
console.log("systems length 0")
loaded = true;
systems[0] = new Object();
systems[0].Gzone = Gzone;
systems[0].Gsource = Gsource;
systems[0].Ggroup = Ggroup;
systems[0].presets = [];
systems[0].shortcuts = {
0: 12,
1: 12,
2: 12,
3: 12
};
systems[0].sources = [];
systems[0].zones = [];
systems[0].groups = [];
//systems[0].customShortcuts = customShortcuts;
localStorage.setItem("systems", JSON.stringify(systems))
} else {
for (i = 0; i < systems.length; i++) {
if (systems[i].groups) {
systems[i].groups.sort(function(a, b) {
return a.name.localeCompare(b.name)
});
if (systems[i].presets) {
systems[i].presets.sort(function(a, b) {
return a.name.localeCompare(b.name)
});
}
}
// if (systems[i].presets) {
// systems[i].presets.sort((a, b) => a.name.localeCompare(b.name));
// }
if (systems[i].system.uuid == uuid) {
loaded = true;
//console.log("updating system data " + i)
systems[i].Gzone = Gzone;
systems[i].Gsource = Gsource;
systems[i].Ggroup = Ggroup;
//systems[i].presets = presets;
//systems[i].shortcuts = shortcuts;
//systems[i].sources = sources;
//systems[i].zones = zones;
//systems[i].groups = groups;
//systems[i].system = system;
localStorage.setItem("systems", JSON.stringify(systems))
}
}
}
if (loaded == false) {
console.log("add data for first time")
console.log(Gzone, systems.length);
systems[systems.length] = new Object();
}
}