Skip to content

Commit

Permalink
change endpoints, comment unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
mel1na committed Nov 18, 2024
1 parent f095fe5 commit d66c5da
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
}
Expand All @@ -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);
Expand All @@ -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");
}
Expand Down

0 comments on commit d66c5da

Please sign in to comment.