feat: Backend support for Edge commands/failsafe
Some checks are pending
Test / backend-test (push) Waiting to run
Test / frontend-test (push) Waiting to run

This commit is contained in:
fullsizemalt 2026-01-05 23:17:03 -08:00
parent 22d0668ba1
commit 6ae2b35f8d

View file

@ -521,9 +521,27 @@ export async function environmentRoutes(fastify: FastifyInstance) {
fastify.log.warn(`Edge device ${data.edgeId} status: ${data.status}`);
}
// Check for unaddressed critical temperature alerts (> 15 mins)
const fifteenMinsAgo = new Date(Date.now() - 15 * 60 * 1000);
const criticalAlert = await prisma.environmentAlert.findFirst({
where: {
type: 'TEMPERATURE_HIGH',
resolvedAt: null,
acknowledgedAt: null,
createdAt: { lt: fifteenMinsAgo }
}
});
const commands: any[] = [];
if (criticalAlert) {
fastify.log.warn(`🚨 Failsafe triggered for alert ${criticalAlert.id}! Sending Kasa ON command to edge.`);
commands.push({ type: 'toggle_plug', state: true });
}
return {
ack: true,
serverTime: new Date().toISOString()
serverTime: new Date().toISOString(),
commands
};
} catch (error) {
fastify.log.error(error);