true
This commit is contained in:
parent
da020ca30f
commit
d1dd787ba9
32
src/index.ts
32
src/index.ts
|
@ -18,17 +18,22 @@ const ledRed = new Gpio(Number(process.env.GPIO_RED || 14), "out");
|
||||||
const ledGreen = new Gpio(Number(process.env.GPIO_GREEN || 15), "out");
|
const ledGreen = new Gpio(Number(process.env.GPIO_GREEN || 15), "out");
|
||||||
|
|
||||||
const monitors: { [key: string]: { status: boolean, index: number } } = {};
|
const monitors: { [key: string]: { status: boolean, index: number } } = {};
|
||||||
const paused: { [key: string]: boolean } = {};
|
let paused: { [key: string]: boolean } = {};
|
||||||
|
|
||||||
const socket = io(`${KUMA_URL}`);
|
const socket = io(`${KUMA_URL}`);
|
||||||
|
|
||||||
socket.on("monitorList", (items) => {
|
socket.on("monitorList", (items) => {
|
||||||
console.log("got monitor list");
|
console.log("got monitor list");
|
||||||
|
|
||||||
|
paused = {};
|
||||||
|
|
||||||
for (const item of Object.values(items) as any[]) {
|
for (const item of Object.values(items) as any[]) {
|
||||||
paused[item.id] = item.active == 0 || item.type == "group";
|
if (item.type == "group") continue;
|
||||||
|
paused[item.id] = item.active == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(Object.keys(paused));
|
||||||
|
|
||||||
think();
|
think();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,7 +109,7 @@ function setStatus(status: Status, sound = true) {
|
||||||
|
|
||||||
function think() {
|
function think() {
|
||||||
const down = Object.entries(monitors)
|
const down = Object.entries(monitors)
|
||||||
.filter(m => !m[1].status && !paused[m[0]]);
|
.filter(m => !m[1].status && paused[m[0]] === false);
|
||||||
|
|
||||||
if (down.length) {
|
if (down.length) {
|
||||||
if (currentStatus != "red") setStatus("red");
|
if (currentStatus != "red") setStatus("red");
|
||||||
|
@ -114,3 +119,24 @@ function think() {
|
||||||
}
|
}
|
||||||
|
|
||||||
setStatus("working");
|
setStatus("working");
|
||||||
|
|
||||||
|
setInterval(async () => {
|
||||||
|
if (currentStatus == "green") {
|
||||||
|
ledGreen.writeSync(NO_GREEN ? 1 : 0);
|
||||||
|
await sleep(50);
|
||||||
|
ledGreen.writeSync(NO_GREEN ? 0 : 1);
|
||||||
|
}
|
||||||
|
else if (currentStatus == "red") {
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
ledRed.writeSync(0);
|
||||||
|
await sleep(50);
|
||||||
|
ledRed.writeSync(1);
|
||||||
|
await sleep(50);
|
||||||
|
}
|
||||||
|
|
||||||
|
// in case the status changed while we were flashing the LED
|
||||||
|
if (currentStatus != "red") {
|
||||||
|
setStatus(currentStatus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
|
Loading…
Reference in a new issue