Disable Identify for same serial device (#1737)

This commit is contained in:
LordGrey 2024-05-09 11:51:00 +02:00 committed by GitHub
parent cf287f5adb
commit 0a93af95c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1053,28 +1053,28 @@ $(document).ready(function () {
}); });
$("#leddevices").off().on("change", function () { $("#leddevices").off().on("change", function () {
var generalOptions = window.serverSchema.properties.device; const generalOptions = window.serverSchema.properties.device;
var ledType = $(this).val(); const ledType = $(this).val();
var specificOptions = window.serverSchema.properties.alldevices[ledType]; const specificOptions = window.serverSchema.properties.alldevices[ledType];
conf_editor = createJsonEditor('editor_container_leddevice', { conf_editor = createJsonEditor('editor_container_leddevice', {
specificOptions: specificOptions, specificOptions: specificOptions,
generalOptions: generalOptions, generalOptions: generalOptions,
}); });
var values_general = {}; let values_general = {};
var values_specific = {}; let values_specific = {};
var isCurrentDevice = (window.serverConfig.device.type == ledType); const isCurrentDevice = (window.serverConfig.device.type == ledType);
for (var key in window.serverConfig.device) { for (const key in window.serverConfig.device) {
if (key != "type" && key in generalOptions.properties) values_general[key] = window.serverConfig.device[key]; if (key != "type" && key in generalOptions.properties) values_general[key] = window.serverConfig.device[key];
}; };
conf_editor.getEditor("root.generalOptions").setValue(values_general); conf_editor.getEditor("root.generalOptions").setValue(values_general);
if (isCurrentDevice) { if (isCurrentDevice) {
var specificOptions_val = conf_editor.getEditor("root.specificOptions").getValue(); const specificOptions_val = conf_editor.getEditor("root.specificOptions").getValue();
for (var key in specificOptions_val) { for (const key in specificOptions_val) {
values_specific[key] = (key in window.serverConfig.device) ? window.serverConfig.device[key] : specificOptions_val[key]; values_specific[key] = (key in window.serverConfig.device) ? window.serverConfig.device[key] : specificOptions_val[key];
}; };
conf_editor.getEditor("root.specificOptions").setValue(values_specific); conf_editor.getEditor("root.specificOptions").setValue(values_specific);
@ -1089,9 +1089,9 @@ $(document).ready(function () {
createLedDeviceWizards(ledType); createLedDeviceWizards(ledType);
conf_editor.on('ready', function () { conf_editor.on('ready', function () {
var hwLedCountDefault = 1; let hwLedCountDefault = 1;
var colorOrderDefault = "rgb"; let colorOrderDefault = "rgb";
var filter = {}; let filter = {};
$('#btn_layout_controller').hide(); $('#btn_layout_controller').hide();
$('#btn_test_controller').hide(); $('#btn_test_controller').hide();
@ -1139,58 +1139,55 @@ $(document).ready(function () {
.catch(error => { .catch(error => {
showNotification('danger', "Device discovery for " + ledType + " failed with error:" + error); showNotification('danger', "Device discovery for " + ledType + " failed with error:" + error);
}); });
hwLedCountDefault = 1;
colorOrderDefault = "rgb";
break; break;
case "philipshue": case "philipshue": {
disableAutoResolvedGeneralOptions(); disableAutoResolvedGeneralOptions();
var lights = conf_editor.getEditor("root.specificOptions.lightIds").getValue(); const lights = conf_editor.getEditor("root.specificOptions.lightIds").getValue();
hwLedCountDefault = lights.length; hwLedCountDefault = lights.length;
colorOrderDefault = "rgb"; }
break; break;
case "yeelight": case "yeelight": {
disableAutoResolvedGeneralOptions(); disableAutoResolvedGeneralOptions();
var lights = conf_editor.getEditor("root.specificOptions.lights").getValue(); const lights = conf_editor.getEditor("root.specificOptions.lights").getValue();
hwLedCountDefault = lights.length; hwLedCountDefault = lights.length;
colorOrderDefault = "rgb"; }
break; break;
case "atmoorb": case "atmoorb": {
disableAutoResolvedGeneralOptions(); disableAutoResolvedGeneralOptions();
var configruedOrbIds = conf_editor.getEditor("root.specificOptions.orbIds").getValue().trim(); const configruedOrbIds = conf_editor.getEditor("root.specificOptions.orbIds").getValue().trim();
if (configruedOrbIds.length !== 0) { if (configruedOrbIds.length !== 0) {
hwLedCountDefault = configruedOrbIds.split(",").map(Number).length; hwLedCountDefault = configruedOrbIds.split(",").map(Number).length;
} else { } else {
hwLedCountDefault = 0; hwLedCountDefault = 0;
} }
colorOrderDefault = "rgb"; }
break; break;
case "razer": case "razer": {
disableAutoResolvedGeneralOptions(); disableAutoResolvedGeneralOptions();
hwLedCountDefault = 1;
colorOrderDefault = "bgr"; colorOrderDefault = "bgr";
var subType = conf_editor.getEditor("root.specificOptions.subType").getValue(); const subType = conf_editor.getEditor("root.specificOptions.subType").getValue();
let params = { subType: subType }; const params = { subType };
getProperties_device(ledType, subType, params); getProperties_device(ledType, subType, params);
}
break; break;
default: default:
} }
if (ledType !== window.serverConfig.device.type) { if (ledType !== window.serverConfig.device.type) {
var hwLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount"); let hwLedCount = conf_editor.getEditor("root.generalOptions.hardwareLedCount");
if (hwLedCount) { if (hwLedCount) {
hwLedCount.setValue(hwLedCountDefault); hwLedCount.setValue(hwLedCountDefault);
} }
var colorOrder = conf_editor.getEditor("root.generalOptions.colorOrder"); let colorOrder = conf_editor.getEditor("root.generalOptions.colorOrder");
if (colorOrder) { if (colorOrder) {
colorOrder.setValue(colorOrderDefault); colorOrder.setValue(colorOrderDefault);
} }
@ -1199,8 +1196,8 @@ $(document).ready(function () {
conf_editor.on('change', function () { conf_editor.on('change', function () {
// //Check, if device can be identified/tested and/or saved // //Check, if device can be identified/tested and/or saved
var canIdentify = false; let canIdentify = false;
var canSave = false; let canSave = false;
switch (ledType) { switch (ledType) {
@ -1212,11 +1209,12 @@ $(document).ready(function () {
case "udpartnet": case "udpartnet":
case "udpddp": case "udpddp":
case "udph801": case "udph801":
case "udpraw": case "udpraw": {
var host = conf_editor.getEditor("root.specificOptions.host").getValue(); const host = conf_editor.getEditor("root.specificOptions.host").getValue();
if (host !== "") { if (host !== "") {
canSave = true; canSave = true;
} }
}
break; break;
case "adalight": case "adalight":
@ -1224,50 +1222,63 @@ $(document).ready(function () {
case "karate": case "karate":
case "dmx": case "dmx":
case "sedu": case "sedu":
case "tpm2": case "tpm2": {
var rate = conf_editor.getEditor("root.specificOptions.rate").getValue(); let currentDeviceType = window.serverConfig.device.type;
if ($.inArray(currentDeviceType, devSerial) === -1) {
canIdentify = true;
} else {
let output = conf_editor.getEditor("root.specificOptions.output").getValue();
if (window.serverConfig.device.output !== output) {
canIdentify = true;
}
}
const rate = conf_editor.getEditor("root.specificOptions.rate").getValue();
if (rate > 0) { if (rate > 0) {
canSave = true; canSave = true;
} }
}
break; break;
case "philipshue": case "philipshue": {
var host = conf_editor.getEditor("root.specificOptions.host").getValue(); const host = conf_editor.getEditor("root.specificOptions.host").getValue();
var username = conf_editor.getEditor("root.specificOptions.username").getValue(); const username = conf_editor.getEditor("root.specificOptions.username").getValue();
if (host !== "" && username != "") { if (host !== "" && username != "") {
var useEntertainmentAPI = conf_editor.getEditor("root.specificOptions.useEntertainmentAPI").getValue(); const useEntertainmentAPI = conf_editor.getEditor("root.specificOptions.useEntertainmentAPI").getValue();
var clientkey = conf_editor.getEditor("root.specificOptions.clientkey").getValue(); const clientkey = conf_editor.getEditor("root.specificOptions.clientkey").getValue();
if (!useEntertainmentAPI || clientkey !== "") { if (!useEntertainmentAPI || clientkey !== "") {
canSave = true; canSave = true;
} }
} }
}
break; break;
case "wled": case "wled":
case "cololight": case "cololight": {
var hostList = conf_editor.getEditor("root.specificOptions.hostList").getValue(); const hostList = conf_editor.getEditor("root.specificOptions.hostList").getValue();
if (hostList !== "SELECT") { if (hostList !== "SELECT") {
var host = conf_editor.getEditor("root.specificOptions.host").getValue(); const host = conf_editor.getEditor("root.specificOptions.host").getValue();
if (host !== "") { if (host !== "") {
canIdentify = true; canIdentify = true;
canSave = true; canSave = true;
} }
} }
}
break; break;
case "nanoleaf": case "nanoleaf": {
var hostList = conf_editor.getEditor("root.specificOptions.hostList").getValue(); const hostList = conf_editor.getEditor("root.specificOptions.hostList").getValue();
if (hostList !== "SELECT") { if (hostList !== "SELECT") {
var host = conf_editor.getEditor("root.specificOptions.host").getValue(); const host = conf_editor.getEditor("root.specificOptions.host").getValue();
var token = conf_editor.getEditor("root.specificOptions.token").getValue(); const token = conf_editor.getEditor("root.specificOptions.token").getValue();
if (host !== "" && token !== "") { if (host !== "" && token !== "") {
canIdentify = true; canIdentify = true;
canSave = true; canSave = true;
} }
} }
}
break; break;
default: default:
canIdentify = false;
canSave = true; canSave = true;
} }
@ -1395,30 +1406,27 @@ $(document).ready(function () {
} }
}); });
conf_editor.watch('root.specificOptions.output', () => { conf_editor.watch('root.specificOptions.output', () => {
var output = conf_editor.getEditor("root.specificOptions.output").getValue(); const output = conf_editor.getEditor("root.specificOptions.output").getValue();
if (output === "NONE" || output === "SELECT" || output === "") { if (output === "NONE" || output === "SELECT" || output === "") {
$('#btn_submit_controller').prop('disabled', true); $('#btn_submit_controller').prop('disabled', true);
$('#btn_test_controller').prop('disabled', true); $('#btn_test_controller').prop('disabled', true);
$('#btn_test_controller').hide(); $('#btn_test_controller').hide();
conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(1); conf_editor.getEditor("root.generalOptions.hardwareLedCount").setValue(1);
showAllDeviceInputOptions("output", false); showAllDeviceInputOptions("output", false);
} }
else { else {
showAllDeviceInputOptions("output", true); showAllDeviceInputOptions("output", true);
let params = {}; let params = {};
var canIdentify = false;
switch (ledType) { switch (ledType) {
case "adalight":
canIdentify = true;
break;
case "atmo": case "atmo":
case "karate": case "karate":
params = { serialPort: output }; params = { serialPort: output };
getProperties_device(ledType, output, params); getProperties_device(ledType, output, params);
break; break;
case "adalight":
case "dmx": case "dmx":
case "sedu": case "sedu":
case "tpm2": case "tpm2":
@ -1437,8 +1445,8 @@ $(document).ready(function () {
} }
if ($.inArray(ledType, devSerial) != -1) { if ($.inArray(ledType, devSerial) != -1) {
var rateList = conf_editor.getEditor("root.specificOptions.rateList").getValue(); const rateList = conf_editor.getEditor("root.specificOptions.rateList").getValue();
var showRate = false; let showRate = false;
if (rateList == "CUSTOM") { if (rateList == "CUSTOM") {
showRate = true; showRate = true;
} }
@ -1446,13 +1454,6 @@ $(document).ready(function () {
} }
if (!conf_editor.validate().length) { if (!conf_editor.validate().length) {
if (canIdentify) {
$("#btn_test_controller").show();
$('#btn_test_controller').prop('disabled', false);
} else {
$('#btn_test_controller').hide();
$('#btn_test_controller').prop('disabled', true);
}
if (!window.readOnlyMode) { if (!window.readOnlyMode) {
$('#btn_submit_controller').prop('disabled', false); $('#btn_submit_controller').prop('disabled', false);
} }
@ -1504,12 +1505,12 @@ $(document).ready(function () {
}); });
conf_editor.watch('root.specificOptions.rateList', () => { conf_editor.watch('root.specificOptions.rateList', () => {
var specOptPath = 'root.specificOptions.'; const specOptPath = 'root.specificOptions.';
var rateList = conf_editor.getEditor("root.specificOptions.rateList"); const rateList = conf_editor.getEditor("root.specificOptions.rateList");
if (rateList) { let rate = conf_editor.getEditor("root.specificOptions.rate");
var val = rateList.getValue();
var rate = conf_editor.getEditor("root.specificOptions.rate");
if (rateList) {
const val = rateList.getValue();
switch (val) { switch (val) {
case 'CUSTOM': case 'CUSTOM':
case '': case '':