compose.yml für dockge dazu
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user