Fix station status updating
This commit is contained in:
parent
170fee4fa5
commit
c8e047e23b
@ -33,13 +33,6 @@ const props = defineProps({
|
|||||||
now: Date,
|
now: Date,
|
||||||
});
|
});
|
||||||
|
|
||||||
const stationStatus = ref({
|
|
||||||
lastHeard: null,
|
|
||||||
delta: null,
|
|
||||||
lastVoltage: null,
|
|
||||||
lastTemperature: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
function notify(title, body) {
|
function notify(title, body) {
|
||||||
return new Notification(title, { body: body, requireInteraction: true });
|
return new Notification(title, { body: body, requireInteraction: true });
|
||||||
}
|
}
|
||||||
@ -73,12 +66,13 @@ const tacticalAndOrCall = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const timedOut = computed(() => {
|
const timedOut = computed(() => {
|
||||||
if (!stationStatus.value.lastHeard) {
|
if (stationStatus.value.lastHeard === null) {
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
props.now.getTime() - stationStatus.value.lastHeard > config.timeoutLength
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let nowDelta = new Date(props.now.value - stationStatus.value.lastHeard);
|
|
||||||
return nowDelta.getTime() > config.timeoutLength;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const lowVoltage = computed(() => {
|
const lowVoltage = computed(() => {
|
||||||
@ -88,32 +82,37 @@ const lowVoltage = computed(() => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
const stationStatus = computed(() => {
|
||||||
() => props.messages,
|
const status = {
|
||||||
() => {
|
lastHeard: null,
|
||||||
Object.assign(
|
delta: null,
|
||||||
stationStatus.value,
|
lastVoltage: null,
|
||||||
props.messages.reduce((acc, message, idx, arr) => {
|
lastTemperature: null,
|
||||||
acc.lastHeard = message.date.getTime();
|
};
|
||||||
if (idx === 0) {
|
|
||||||
acc.avgDelta = 0;
|
Object.assign(
|
||||||
} else {
|
status,
|
||||||
let delta = message.date.getTime() - arr[idx - 1].date.getTime();
|
props.messages.reduce((acc, message, idx, arr) => {
|
||||||
acc.avgDelta = (acc.avgDelta * (idx - 1) + delta) / idx;
|
acc.lastHeard = message.date.getTime();
|
||||||
|
if (idx === 0) {
|
||||||
|
acc.avgDelta = 0;
|
||||||
|
} else {
|
||||||
|
let delta = message.date.getTime() - arr[idx - 1].date.getTime();
|
||||||
|
acc.avgDelta = (acc.avgDelta * (idx - 1) + delta) / idx;
|
||||||
|
}
|
||||||
|
if ('data' in message) {
|
||||||
|
if ('analog' in message.data) {
|
||||||
|
acc.lastVoltage = message.data.analog[0] / 10;
|
||||||
|
acc.lastTemperature = message.data.analog[1];
|
||||||
}
|
}
|
||||||
if ('data' in message) {
|
acc.lastMicE = message.data.mice || acc.lastMicE;
|
||||||
if ('analog' in message.data) {
|
acc.lastComment = message.data.comment || acc.lastComment;
|
||||||
acc.lastVoltage = message.data.analog[0] / 10;
|
}
|
||||||
acc.lastTemperature = message.data.analog[1];
|
return acc;
|
||||||
}
|
}, {})
|
||||||
acc.lastMicE = message.data.mice || acc.lastMicE;
|
);
|
||||||
acc.lastComment = message.data.comment || acc.lastComment;
|
return status;
|
||||||
}
|
});
|
||||||
return acc;
|
|
||||||
}, {})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.lowVoltage,
|
() => props.lowVoltage,
|
||||||
|
Loading…
Reference in New Issue
Block a user