feat: Backend support for Edge commands/failsafe
This commit is contained in:
parent
22d0668ba1
commit
6ae2b35f8d
1 changed files with 19 additions and 1 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue