diff --git a/scripts.js b/scripts.js index bc50ab7..6557646 100644 --- a/scripts.js +++ b/scripts.js @@ -30,14 +30,15 @@ const labstatusElem = document.getElementById("labstatus"); const labstatusOverlayElem = labstatusElem.closest(".labstatus-overlay"); async function refreshLabStatus() { - const res = await fetch("https://metalab-status.gupper.systems/lab"); + const res = await fetch("https://eingang.metalab.at/status.json"); if (!res.ok) { throw new Error("Unexpected error status: " + res.status) } const labstatus_json = await res.json(); - var hass_state = labstatus_json.state; + let lab_state = labstatus_json.status; + /*var hass_state = labstatus_json.state; var hass_last_changed_date = new Date(labstatus_json.last_changed_utc); var hass_last_updated_date = new Date(labstatus_json.last_updated_utc); @@ -53,24 +54,27 @@ async function refreshLabStatus() { //return localized and formatted date var hass_last_changed_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_changed_date); - var hass_last_updated_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_updated_date); + var hass_last_updated_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_updated_date);*/ - if (hass_state === "on") { + //if (hass_state === "on") { + if (lab_state === "open") { labstatusElem.innerHTML = STRINGS.open[selectedLang]; - labstatusOverlayElem.title = STRINGS.open_since[selectedLang] + hass_last_changed_date_formatted; + //labstatusOverlayElem.title = STRINGS.open_since[selectedLang] + hass_last_changed_date_formatted; labstatusElem.classList.add('open'); - } else if (hass_state === "off") { + //} else if (hass_state === "off") { + } else if (lab_state === "closed") { labstatusElem.innerHTML = STRINGS.closed[selectedLang]; - labstatusOverlayElem.title = STRINGS.closed_since[selectedLang] + hass_last_changed_date_formatted; + //labstatusOverlayElem.title = STRINGS.closed_since[selectedLang] + hass_last_changed_date_formatted; labstatusElem.classList.add('closed'); } else { - throw new Error("Unexpected lab status: " + hass_state); + //throw new Error("Unexpected lab status: " + hass_state); + throw new Error("Unexpected lab status: " + lab_state); } - if ((new Date().getTime() - hass_last_updated_date.getTime()) >= 900_000) { //15 minutes + /*if ((new Date().getTime() - hass_last_updated_date.getTime()) >= 900_000) { //15 minutes labstatusElem.innerHTML += " (!)"; labstatusOverlayElem.title += "\n" + STRINGS.last_update[selectedLang] + hass_last_updated_date_formatted; - } + }*/ labstatusOverlayElem.classList.remove("failed"); } @@ -88,14 +92,15 @@ const doorElem = document.getElementById("door"); const doorOverlayElem = doorElem.closest(".door-overlay"); async function refreshDoorStatus() { - const res = await fetch("https://metalab-status.gupper.systems/door"); + const res = await fetch("https://eingang.metalab.at/doorstatus.json"); if (!res.ok) { throw new Error("Unexpected error status: " + res.status) } - const labstatus_json = await res.json(); - var hass_state = labstatus_json.state; + const doorstatus_json = await res.json(); + let door_state = doorstatus_json.status; + /*var hass_state = labstatus_json.state; var hass_last_changed_date = new Date(labstatus_json.last_changed_utc); var hass_last_updated_date = new Date(labstatus_json.last_updated_utc); @@ -111,24 +116,27 @@ async function refreshDoorStatus() { //return localized and formatted date var hass_last_changed_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_changed_date); - var hass_last_updated_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_updated_date); + var hass_last_updated_date_formatted = new Intl.DateTimeFormat(undefined, date_options).format(hass_last_updated_date);*/ - if (hass_state === "on") { + //if (hass_state === "on") { + if (door_state === "open") { doorElem.innerHTML = STRINGS.open[selectedLang]; - doorOverlayElem.title = STRINGS.open_since[selectedLang] + hass_last_changed_date_formatted; + //doorOverlayElem.title = STRINGS.open_since[selectedLang] + hass_last_changed_date_formatted; doorElem.classList.add('open'); - } else if (hass_state === "off") { + } else if (door_state === "closed") { + //} else if (hass_state === "off") { doorElem.innerHTML = STRINGS.closed[selectedLang]; - doorOverlayElem.title = STRINGS.closed_since[selectedLang] + hass_last_changed_date_formatted; + //doorOverlayElem.title = STRINGS.closed_since[selectedLang] + hass_last_changed_date_formatted; doorElem.classList.add('closed'); } else { - throw new Error("Unexpected door status: " + hass_state); + //throw new Error("Unexpected door status: " + hass_state); + throw new Error("Unexpected door status: " + door_state); } - if ((new Date().getTime() - hass_last_updated_date.getTime()) >= 900_000) { //15 minutes + /*if ((new Date().getTime() - hass_last_updated_date.getTime()) >= 900_000) { //15 minutes doorElem.innerHTML += " (!)"; doorOverlayElem.title += "\n" + STRINGS.last_update[selectedLang] + hass_last_updated_date_formatted; - } + }*/ doorOverlayElem.classList.remove("failed"); }