compose.yml für dockge dazu

This commit is contained in:
rxf
2026-03-11 11:58:49 +01:00
parent 2739d478f6
commit e01ab276b6
10 changed files with 2078 additions and 1301 deletions

View File

@@ -5,10 +5,16 @@ $(document).ready(function() {
console.log("Es geht los");
const URL = "switch/";
const checktime = 5000000; // alle 30sec Zustand prüfen
const POLL_INTERVAL_MS = 1000;
const queryToken = new URLSearchParams(window.location.search).get('token');
const storedToken = localStorage.getItem('switchApiToken');
const API_TOKEN = queryToken || storedToken || '';
let interval = null;
let status = "";
let tr;
if (queryToken) {
localStorage.setItem('switchApiToken', queryToken);
}
$('#versn').html("V " + VERSION + ' ' + VDATE); // Vesion anzeigen
@@ -19,13 +25,13 @@ $(document).ready(function() {
// sendCommand(URL,"PowerOnState%200"); // OFF bei Power ON
// sendCommand(URL,"PulseTime%20"+(brenndauer+100)); // Brenndauer einstellen
let interval = setInterval(sendTimedCommand, 1000); // alle Sekunde pollen
startPolling();
document.addEventListener('visibilitychange', function (event) {
if (!document.hidden) {
interval = setInterval(sendTimedCommand, 1000);
startPolling();
} else {
clearTimeout(interval); // The page is hidden.
stopPolling();
}
});
@@ -33,8 +39,7 @@ $(document).ready(function() {
sendCommand(URL, "get_status")
$("#schalter").click(function () {
let message;
if (status == 'ON') {
if (status === 'ON') {
console.log("Sende OFF")
sendCommand(URL, "switch_off")
} else {
@@ -45,18 +50,36 @@ $(document).ready(function() {
function sendCommand(url, cmnd) {
console.log("sendCommand", cmnd);
const p = new Promise((resolve, reject) => {
$.getJSON(url + cmnd, function (data, err) { // AJAX Call
if (err != 'success') {
reject(err);
alert("Fehler <br />" + err); // if error, show it
} else {
let endpoint = url + cmnd;
if (API_TOKEN) {
endpoint += '?token=' + encodeURIComponent(API_TOKEN);
}
return new Promise((resolve, reject) => {
$.getJSON(endpoint)
.done(function (data) {
console.log("gekommen: ", data);
resolve(data);
}
});
})
.fail(function (_jqXHR, textStatus, errorThrown) {
const msg = errorThrown || textStatus || "Unbekannter Fehler";
reject(msg);
});
});
return p;
}
function startPolling() {
if (interval !== null) {
clearInterval(interval);
}
interval = setInterval(sendTimedCommand, POLL_INTERVAL_MS);
}
function stopPolling() {
if (interval !== null) {
clearInterval(interval);
interval = null;
}
}
function sendTimedCommand() {
@@ -65,13 +88,12 @@ $(document).ready(function() {
.then(data => {
// console.log("Timed Status= ", st);
status = data.relais;
if (status != 'pending') {
clearTimeout(tr);
if (status == 'ON') {
if (status !== 'pending') {
if (status === 'ON') {
$('#schalter').html('Laufschrift <b>AUS</b> schalten');
$('#status').text('EIN');
$('#laufzeile').addClass('machrot');
if(data.offtime != undefined) {
if (data.offtime !== undefined) {
$('#auszeit').text(data.offtime);
$('#auszeile').show();
}
@@ -82,6 +104,9 @@ $(document).ready(function() {
$('#auszeile').hide();
}
}
})
.catch(err => {
console.log('Statusabfrage fehlgeschlagen:', err);
});
}