Fix station status updating

This commit is contained in:
Adam Goldsmith 2022-07-09 10:21:26 -04:00
parent 170fee4fa5
commit c8e047e23b

View File

@ -33,13 +33,6 @@ const props = defineProps({
now: Date,
});
const stationStatus = ref({
lastHeard: null,
delta: null,
lastVoltage: null,
lastTemperature: null,
});
function notify(title, body) {
return new Notification(title, { body: body, requireInteraction: true });
}
@ -73,12 +66,13 @@ const tacticalAndOrCall = computed(() => {
});
const timedOut = computed(() => {
if (!stationStatus.value.lastHeard) {
if (stationStatus.value.lastHeard === null) {
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(() => {
@ -88,11 +82,16 @@ const lowVoltage = computed(() => {
);
});
watch(
() => props.messages,
() => {
const stationStatus = computed(() => {
const status = {
lastHeard: null,
delta: null,
lastVoltage: null,
lastTemperature: null,
};
Object.assign(
stationStatus.value,
status,
props.messages.reduce((acc, message, idx, arr) => {
acc.lastHeard = message.date.getTime();
if (idx === 0) {
@ -112,8 +111,8 @@ watch(
return acc;
}, {})
);
}
);
return status;
});
watch(
() => props.lowVoltage,